maven assembly:single doesn't resolve dependency - eclipse

I am trying to make a single jar with all dependencies resolved so that I can run this jar from command prompt. I am using maven's assembly:single but whenever I am doing so, I get an issue
[ERROR] com.XXX.XXXX.XXX:XXX-XXX-XXX:jar:XXX
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] A (http://XXXXX/, releases=true, snapshots=true),
[ERROR] B (http://XXXX/, releases=true, snapshots=true),
[ERROR] C (https://repo.maven.apache.org/maven2/, releases=true, snapshots=true
),
[ERROR] D (https://XXXXX, releases=false, snapshots=true)
[ERROR] Path to dependency:
[ERROR] 1) com.test.Report:myjar:jar:0.0.1-SNAPSHOT
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception
This is the pom I am working with
Now these jars are already resolved and are present in Maven Dependency folder. I can run the whole project from Eclipse but need to give this jar to client with all the jars included. Any help is appreciated. Thanks :)

One approach is to use the "jar-with-dependencies" configuration in your pom.xml. This will package all your dependencies in the jar.
For eg:
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Another approach is to use the maven shade plugin.
For eg:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
The maven shade plugin will basically create two jars at the end. The first jar is the normal jar which contains just the compiled classes of your source code.
The second jar will also contain your compiled classes but it will also include the class files from all your dependencies. This is the jar that you should give to your client.

Ok. Probably no one would be looking at this answer but still I would like to have a note for my future self. This issue was different from what exception I was getting. To run any plugin make sure that <plugin> is inside <plugins> inside <build> (not under <pluginManagement>). Doing this ran the plugin and jar with dependencies was formed upon mvn install.

Related

For a scala compiler, what are the differences between 'Symbol '***' is missing from the classpath' error and 'object *** is not a member' error?

In a recent experiment, I tried to use maven-shade plugin to move all classes in a package com.original.work under a scala library into a different package, and compile into a new project JAR:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadeTestJar>true</shadeTestJar>
<createSourcesJar>true</createSourcesJar>
<shadeSourcesContent>true</shadeSourcesContent>
<createDependencyReducedPom>true</createDependencyReducedPom>
<dependencyReducedPomLocation>
${project.build.directory}/dependency-reduced-pom.xml
</dependencyReducedPomLocation>
<!-- <generateUniqueDependencyReducedPom>true</generateUniqueDependencyReducedPom>-->
<!-- <keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>-->
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<!-- <shadedClassifierName>${spark.classifier}</shadedClassifierName>-->
<!-- <useBaseVersion>true</useBaseVersion>-->
<relocations>
<relocation>
<pattern>com.original.work</pattern>
<shadedPattern>com.relocated.work</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>com.original.work:work</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
Unfortunately, this JAR behave strangely if being used by other scala projects. E.g. if the project 'work' already has a trait defined under a package:
package com.original.work.utils
trait IDMixin {
...
Then for any other scala project that use the new JAR, using IDMixin will fail. Specifically:
If I import com.original.work.utils.IDMixin directly, I will get the following exception:
[ERROR] .../ExampleOld.scala:4: object original is not a member of package com
[ERROR] object ExampleOld extends com.original.work.utils.IDMixin{}
[ERROR] ^
If I import com.relocated.work.utils.IDMixin, I will get the following exception:
[ERROR] .../Example.scala:3: Symbol 'term com.original.work.utils' is missing from the classpath.
This symbol is required by ' <none>'.
Make sure that term utils is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'IDMixin.class' was compiled against an incompatible version of com.original.work.
So my questions are:
What are the differences between these 2 error information?
If this problem is caused by maven-shade plugin, what should I do to fix it? If not possible, are there any other build tools (sbt, gradle, mill) capable of completing the relocation job?
Thanks a lot for your opinion

Creating Windows Executable for OpenJFX 11 Project in Eclipse with Maven Integration

I'm switching over from Java 8 (Oracle JDK) to OpenJDK 11 and OpenJFX 11. I've successfully gotten my project to work in Eclipse through Maven via the clean javafx:run command using the maven-compiler-plugin however I am having issues building a runnable jar and windows executable. I do not need a linux or mac runnable as this project is just an internal product and we only use windows.
I have already tried several plugins such as the maven-shade-plugin and also tried running mvm package to no avail. I've tried this Build executable JAR with JavaFX11 from maven and this How to deploy a JavaFX 11 Desktop application with a JRE.
In the past I could just build a executable jar through Eclipse's "Export Runnable Jar" option and then creating an executable through launch4j, however this does not seem to work anymore and I understand this probably due to the modular structure of OpenJDk 9+.
I have all the JavaFX dependencies added as well as the JAXB ones that I needed and it runs in the IDE when I build it (although I can't get it to run as a Java Application Run Configuration once I made it run in Maven Run Configuration.
Here are my plugins:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>com.tapestry.testertools.ApplicationMainFrame</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.tapestry.testertools.ApplicationMainFrame</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Here is the error message when i attempt to run mvn clean package
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.325 s
[INFO] Finished at: 2019-09-20T09:19:35-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project testertools: Fatal error compiling: invalid flag: --module-path -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

How to build a Maven project with Eclipse with a pom.xml that imports an external properties file?

I have looked around from various questions on stackoverflow, but I have not found the answer that solve my purpose.
I want to import a properties file in a pom.xml; my purpose is to replace the <properties> section with the properties loaded from the external file.
Each property refers to the version of a particular maven dependency.
I have tried the properties-maven-plugin, but the properties are not solved and the project is not built.
I'm looking for a way that preserve the standard build of Eclipse, and also the mvn install goal of Maven.
As an example, I want that this section:
<properties>
<dependency1.version>1.0.0</dependency1.version>
</properties>
will be replaced with the property declared in a dependency.properties file, like this one:
dependency1.version=1.0.0
How can I implement my pom.xml in order to obtain this behaviour?
Thanks in advance.
EDIT
This is what I have tried:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/dependencies.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>my version: ${dependency1.version}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Well, if I do a simple mvn install, in maven console it prints:
[INFO] Executing tasks
[echo] my version: 1.0.0
[INFO] Executed tasks
So, the plugin solve the property, but when I try to import the dependency with this:
<dependencies>
<dependency>
<groupId>dependency1</groupId>
<artifactId>dependency1</artifactId>
<version>${dependency1.version}</version>
</dependency>
</dependencies>
I obtain this error:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for dependency1:dependency1:jar must be a valid version but is '${dependency1.version}'. # line 21, column 13
#
The property is solved in the maven-antrun-plugin, but if it is used in the dependencies section, it doesn't work.

m2e shade eclipse "project main artifact does not exist"

I'm trying to make a deployment package that bundles all the dependencies of my maven module that has dependencies to another maven project in eclipse.
I have this in my pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.proj</groupId>
<artifactId>AAA</artifactId>
<version>0.0.2-SNAPSHOT</version>
<name>btc</name>
<dependencies>
<dependency>
<groupId>com.another.proj</groupId>
<artifactId>BBB</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.group.id.Launcher1</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I use that "m2 Maven Build" in eclipse with the goal "org.apache.maven.plugins:maven-shade-plugin:shade" and the "Resolve Workspace artifacts" ticked.
It's failing with
--- maven-shade-plugin:1.6:shade (default-cli) # AAA ---
[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR] supported. Please add the goal to the default lifecycle via an
[ERROR] <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR] remove this binding from your POM such that the goal will be run in
[ERROR] the proper phase.
I ran out of idea at this point.
[ERROR] The project main artifact does not exist. This could have the following
We were getting this problem recently. What resolved it for us was to not do mvn shade:shade but instead use:
mvn package
This does additional compilation and package work before running the shade plugin and so the main class was available on the classpath.
The shade plugin is attempting to include the project's artifact in the shaded JAR. Since it doesn't exist (yet), you're getting this error. You either need to build/package the project artifact first (e.g., by attaching the shade goal to the package phase)
If you don't have any project artifact to include in the shaded JAR, you can add an excludes node to remove the project's artifact.
Here's an example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.group.id.Launcher1</mainClass>
</transformer>
</transformers>
<excludes>
<exclude>com.my.proj:AAA</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>

Errors when using maven plugin for Weblogic deployment

I have been trying to deploy application to Weblogic 10.3.6 using maven
I have created weblogic plugin for maven as mentioned in this article.
I have added the following to pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.3</version>
<configuration>
<goalPrefix>weblogic</goalPrefix>
</configuration>
</plugin>
<plugin>
<groupId>weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>10.3.6.0</version>
<configuration>
<adminurl>t3://localdomain:7001</adminurl>
<user>weblogic</user>
<password>password</password>
<name>wldemo</name>
<remote>true</remote>
<upload>true</upload>
<targets>AdminServer</targets>
</configuration>
<executions>
<execution>
<id>deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<source>target/EmployeesApp-1.0-SNAPSHOT.war</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I did mvn com.oracle.weblogic:weblogic-maven-plugin:deploy I am getting the following errors, how can I resolve these errors?
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Final Memory: 3M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.oracle.weblogic:weblogic-maven-plugin:10.3.6.
0:deploy (default-cli) on project EmployeesApp: The parameters 'source' for goal
com.oracle.weblogic:weblogic-maven-plugin:10.3.6.0:deploy are missing or invali
d
You have specified the source parameter in the execution configuration, so in order to make it taken into account you should invoke this particular execution. It can be done using the phase key you specified, so e.g.:
mvn integration-test
Maven will go through the whole lifecycle and on the pre-integration-test test phase (which precedes the integration-test one) it will run the execution of weblogic-maven-plugin you configured.