maven-assembly-plugin is not able to pick up unirest-java as a dependency - maven

I followed the official doc of Unirest-Java and added it as a dependency in my pom.xml file.
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>2.3.16</version>
</dependency>
I also have maven-assembly-plugin available in the pom.xml file so as to package all dependencies in a single jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
After running mvn clean compile assembly:single, I tried to inspect the built jar with jar tf myapp.jar and strangely wasn't able to find any unirest class.
After downgrading to a much lower version, everything worked properly.
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
Also very curious to know why they renamed the groupId to an odd value like com.konghq.

Related

JPMS/Jigsaw keycloak-spring-boot-starter (invalid module name & ResolutionException)

the Java 11 maven application is modularized with JPMS/Jigsaw.
Problem 1: keycloak-spring-boot-2-adapter invalid module-name '2'
Solution 1: Renamed by maven plugin with removed "-2". But I'm not sure if this is a good solution.
<plugin>
<!-- for copying dependent libraries to folder lib -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>../lib</outputDirectory>
<excludeGroupIds>com.xyz</excludeGroupIds>
<excludeArtifactIds>keycloak-spring-boot-2-adapter</excludeArtifactIds>
</configuration>
</execution>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifacItem>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-2-adapter</artifactId>
<overWrite>true</overWrite>
<outputDirectory>../lib</outputDirectory>
<destFileName>keycloak-spring-boot-adapter-9.0.2.jar</destFileName>
</artifacItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
Problem 2: keycloak.spring.boot.adapter and keycloak.spring.boot.adapter.core have the same package name.
java.lang.module.ResolutionException: Modules keycloak.spring.boot.adapter and keycloak.spring.boot.adapter.core export package org.keycloak.adapters.springboot to module org.yaml.snakeyaml
Solution 2: ?
Thanks for your help and best regards,
Pierre
There is a ticket (KEYCLOAK-12499) with two sub tasks describing the two problems you're facing: KEYCLOAK-9072 (Problem 1) and KEYCLOAK-9073 (Problem 2).
The first problem is a trivial one, both from your perspective as from the perspective of the maintainers of Keycloak.
The second problem however requires more work because two (actually three) artifacts are sharing the same package and are exporting it when they are used as automatic modules (because automatic modules export all of their packages).
Exporting the same package from more than one module is not allowed however (http://openjdk.java.net/projects/jigsaw/spec/reqs/#non-interference).
The three artifacts involved in this problem are keycloak-spring-boot-adapter-core, keycloak-spring-boot-adapter and keycloak-spring-boot-2-adapter. The adapter-core artifact works somewhat like an abstract implementation for the two other modules and provides package private classes and methods which are used by the other two modules.
The emphasized text is the core of the second problem: sharing a package across different artifacts works for classic Java without modules, but the module system blocks this because it breaks encapsulation.
Solving the second problem requires you to make copies of keycloak-spring-boot-adapter-core and keycloak-spring-boot-2-adapter and adjust their code — at least until there is a fix for the official artifacts.
A solution for problem 2 is building an own automatic module.
Create a new module and add a POM with the following build plugins and dependency.
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-2-adapter</artifactId>
<version>9.0.2</version>
<exclusions>
<exclusion>
<groupId> org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
...
</exclusions>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
</plugin>
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>../mods</outputDirectory>
<archive>
<manifestEntries>
<Automatic-Module-Name>modulename</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-external</id>
<phase>install</phase>
<configuration>
<file>${project.basedir}/../mods/modulename-1.0-SNAPSHOT.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.xyz.assembly</groupId>
<artifactId>modulename</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You can add the dependency via com.xyz.assembly as groupID to other modules.
But keep attention!
It will use the module-info.java of log4j if you don't exclude it in this assembly module.

JavaFX Application with Maven in Eclipse

I want to ask if there is any method to add JavaFX into Maven Archetype list in Eclipse or any plugin to use Maven to build JavaFX Application.
There is the javafx-maven-plugin which is available for maven.
When developing with Java 8 you just put that plugin as some build-plugin, without further dependencies.
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<mainClass>your.main.class.which.extends.javafx.Application</mainClass>
</configuration>
</plugin>
Calling mvn jfx:jar creates your javafx-application-jar inside target/jfx/app/yourapp-jfx.jar, or even creates native launcher (like EXE-file) when calling mvn jfx:native.
Disclaimer: I'm the maintainer of the javafx-maven-plugin.
The only thing I add to my pom.xml in order to build JavaFX Application is this dependency :
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.2</version>
<systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
<scope>system</scope>
</dependency>
It is simply fetching the javafx jar in my Java8 JRE to add it to the project.
Then I use the maven-assembly-plugin to build the jar with dependencies.
Hope it helps.
This answer is copied from the documentation at https://openjfx.io/openjfx-docs/#maven. More detailed information (including a full sample pom.xml reference) is available at the link provided.
The pom uses the JavaFX Maven plugin:
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>HelloFX</mainClass>
</configuration>
</plugin>
</plugins>
Add the maven dependencies:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
</dependencies>
Run the application (e.g. based on the HelloFX.java from the referred sample):
mvn clean javafx:run
Note regarding other outdated answers
Previous (highly-voted) answers which reference the com.zenjava javafx-maven-plugin are outdated, as that plugin is not coded to work with recent JavaFX versions. For Java versions 10+, the org.openjfx javafx-maven-plugin should be used.
Also, for Java 10+, answers which reference only the assembly plugin and state that JavaFX is included in the JDK, are also outdated. JavaFX is no longer bundled in recent JDK releases, instead it is available as a separate SDK from openjfx.io or as a set of library dependencies from the maven central repository.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
just do as a common Java application because JavaFX version jumped to 8.0. Supports for JavaFX are built-in.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>run application</id>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>cn.keepfight.intro.FXParamApp</mainClass>
<arguments>
<!--<argument>-Dsun.java2d.opengl=true</argument>-->
</arguments>
</configuration>
</execution>
</executions>
</plugin>

Wildfly, fat jar and jndi-registration

When I build a fat jar with my ejb and dependencies, all the dependent libs/jars are unpacked, and when deployed to wildfly, jodi-registration is performed, and entries like
java:global/template-service-1.0.0-SNAPSHOT-jar-with-dependencies/ReceptionService
are reported on the console. I can then add a module dependency to my war-project manifest and use the ejb.
When I build the exact same ejb using one-jar plugin, the dependent libraries are not unpacked, and jndi-registration is not performed. Hence the ejb is not reachable.
From what I can se the jar files are otherwise similar, and it seems wildfly behaves different depending if included jars are unpacked or not. Is this so, and why? Or does the one-jar plugin create a fat jar that is different in some way that I have not figured out?
The pom.xml is listed below, with the one-jar config that I use commented out:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Includes the runtime dependencies -->
<!--
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<attachToBuild>true</attachToBuild>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
-->

dozer with maven

I wanted to download the latest release of Dozer mapper from github, but I didn't find any jar.
There is pom.xml file and I try to compile with command mvn package. I also added every dependencies to pom.xml file. It created dozer-5.5.0-SNAPSHOT.jar.
Next I imported this jar to my project, but it throws me java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory.
I also tried to create POM project in the netbeans and build with dependencies. After import to my project, it throws me the same exception.
I don't have any experiences with maven. How can I get correct JAR file?
Guess your dozer-package has a dependency to slf4j, right?
Then you should checkout this Maven-Plugin: Maven-Assembly-Plugin
This will put your required dependencies into the jar.
Here you can read, how to use it
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>your.main.class</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
If you want always execute the assemby-plugin when you invoke mvn clean package
add this to your maven-assembly-plugin:
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
You have a correct jar. Simple add commons-beanutils lang and slf4j to you project with dozer or add this libraries as a maven dependencies.
Jars required for Dozer dependency.
Make the entry in pom.xml file.Make sure the required Jars are present.
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.3.1</version>
</dependency>
<properties>
<osgi.version>4.3.0</osgi.version>

Invoke a jar file in the M2 repository

I have a project, in which I want to invoke another Jar file in M2 repo during the post execution phase of the current project.
Sample skeleton of my POM
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>exec-one</id>
<phase>verify</phase>
<configuration>
executable>java</executable>
<arguments> <argument>-jar</argument>
<argument>JarToInvoke.jar</argument>
</arguments>
<**workingDirectory**>/C:/path to repo</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<dependencies> <dependency>
<groupId>GroupId of JarToInvoke</groupId>
<artifactId>JarToInvoke</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
I tried with maven-exec-plugin, but having the following issues;
Where I need to specify to JarToInvoke dependency ? As a project dependency or as a exec-plugin dependency ?
With hard coding the working directory(/C:/path to repo), I am able to invoke the JarToInvoke artifact. But it is not a good solution, because finally this project should run in any m/c with different OS's. So how can I make the exec-plugin to search for the JarToInvoke artifact in the M2 repo of the project(default classpath) ?
3.While hard coding the M2 repo path in the working directory, I was able to invoke the JarToInvoke artifact. But while running the JarToInvoke artifact, it throws another dependency issue, some of the log4j dependencies to the JarToInvoke could not find. I made the JarToInvoke as a shaded jar and it work as expected. But it is not a permanent or good solution(Because the shaded jar size is of 35 MB). How can I instruct the exec-plugin to look for the dependent Jars in M2 repo.
Please share your suggestions. Thanks in Advance.
This example page from the Exec plugin's documentation describes what you want I think.
If you could use the exec:java goal instead of exec:exec, finding the JVM is taken care of for you. You can also pull in either plugin dependencies or project dependencies by changing the includeProjectDependencies and includePluginDependencies configuration options of the plugin.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>exec-one</id>
<phase>verify</phase>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>GroupId of JarToInvoke</groupId>
<artifactId>JarToInvoke</artifactId>
</executableDependency>
<!-- Look up the main class from the manifest inside your dependency's JAR -->
<mainClass>com.example.Main</mainClass>
<arguments>
<!-- Add any arguments after your JAR here --->
</arguments>
</configuration>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>GroupId of JarToInvoke</groupId>
<artifactId>JarToInvoke</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
The only disadvantage is that you have to explicitly specify the main class in the JAR to run. You can look this up by opening up the manifest in the dependency JAR and read the Main-Class attribute.
If you really need to use exec:exec, you could use the Maven Dependency Plugin's copy-dependencies goal to copy dependencies from your local repository to a predefined location (such as ${project.build.directory}/exec-jars) and then you can feed this directory in the exec plugin's workingDirectory configuration option.
Probably an easier way to locate the absolute path to the jar file would be to use maven-dependency-plugin with properties goal.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>exec-one</id>
<phase>verify</phase>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${GroupIdofJarToInvoke:JarToInvoke:jar}</argument>
</arguments>
<workingDirectory>/C:/path to repo</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<dependencies>
<dependency>
<groupId>GroupIdofJarToInvoke</groupId>
<artifactId>JarToInvoke</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependencies>

Resources