Copy resulting fat jar to another target folder in Spring boot project - java

I have Spring boot project. Everything is built OK in /target folder but I'd like to change destination folder.
I tried to use maven-jar-plugin as described below but it copies only jar with compiled classes of project (small jar).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${maven.multiModuleProjectDirectory}/output/bin</outputDirectory>
</configuration>
</plugin>
Instead I want to make Maven to copy FAT jar.
Maven builds FAT jar and puts the Jar to /target folder. How to change destination?
UPDATE 1
this is needed by project requirements - need to build folder structure with properties, bash scripts(as entry point) and fat jar:

Try to add this plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
<outputDirectory>${maven.multiModuleProjectDirectory}/output/bin</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

Related

How to rename the jar downloaded as dependency in maven

I am trying to include a jar from the repository but I want to rename the jar when I use it.
Currently I am doing like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<finalName>test</finalName>
<includes>
<include>original-jar-name</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
But there is no effect of the above.
I have already taken help from :
Maven - How to rename the output classifier of a jar name?
Controlling maven final name of jar artifact
Is it possible to rename a maven jar-with-dependencies?
But that did not worked.
How is it achievable ?

Generating a jar and using it as dependency in another module

I have multiple modules in a single project. I have packaged a module as jar and included it as a dependency in another module. I want this jar to be generated and installed in a specific folder.
Dependency of module A included in B
Specifying the folder to copy the jar
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<configuration>
<includeArtifactIds>
<artifactId>rpgenerator</artifactId>
</includeArtifactIds>
<includeGroupIds>
<groupId>a.b.c</groupId>
</includeGroupIds>
<outputDirectory>${project.basedir}/reports/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
But I do not see the jar in the folder B.reports.
Any help would be appreciated.

Maven: jar-with-dependencies include external jar [duplicate]

I want to build a .jar file with dependencies in maven. Unfortunately I have to include some external .jars in my buildpath. When I now try to build this project with maven package I will get an error that those external .jars are not found.
How to adapt my pom file to add those jars?
current:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
You can include the external jars in your build path as dependency with <scope>system</scope>
.
Check this link
You need use below command to add external jar into .m2 folder
mvn install:install-file -Dfile=[JAR] -DgroupId=[some.group] -DartifactId=[Some Id] -Dversion=1.0.0 -Dpackaging=jar
This will add the given jar in to your .m2 folder. After that go to pom.xm and just add the dependency with given group id, artifact id and version.
A simple solution for this is to add it into local maven repository
One way to do is via mvn install commands as suggested in previous post .
Another easy way is,
In your eclipse ide right click on project select Maven option.
Select Install or deploy an artifact to a maven repository option and click on next.
Click on browse next to the Artifact file checkbox & select your jar file.
Enter the GroupId and ArtifactId and version ensure generate pom & create checksum are checked & packaging is jar
Click on finish, Wallah!!! your job is done the jar is added in your local repository which you can define in setting.xml or m2 directory.
Now just add the simple maven dependency as per the GroupId,ArtifactId & jar version that you have entered as per the import and that's it your external jar will be packaged by maven.

How to use maven-jar-plugin to create a test-jar with .class files?

I have been trying to create a test-jar from a war project using the maven-jar-plugin. I have custom src folder which I want as a jar. The plugin does not compile the files in the folder and creates a jar with .java files. How do I compile the java files before they are packaged in a jar as .class files ?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<testClassesDirectory>${project.basedir}/src/test/selenium</testClassesDirectory>
</configuration>
</plugin>
Did you try using maven-compiler-plugin

Force Maven 3 to copy 'provided' dependencies

I use copy-dependencies goal to copy dependencies for current artifact.
But it doesn't copy dependencies with scope 'provided'.
How to fix it?
The xml configuration is standard:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeArtifactIds>project-services</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>project-web</finalName>
</build>
Why do I want to do this?
Because I have to support both ant and maven builds working.
Therefore, I want to copy all dependencies into separate directory by running mvn install -o. In Ant build.xml I include path to that directory as classpath. After that Ant builds ear file and includes whole lib directory withoud system tools.jar and other 'provided' jars.
Version of Apache Maven is 3.0.3
As documented by the plugin use includeScope:
http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html#includeScope
Edit:
Why do I want to do this? Because I have to support both ant and maven
builds working.
Consider to use Ivy to manage your dependencies with Ant:
http://ant.apache.org/ivy/
Here a post how you can configure Ivy to connect to Nexus:
https://support.sonatype.com/entries/21627528-how-do-i-configure-my-ivy-build-to-download-artifacts-from-nexus

Categories

Resources