I am using the following to build up a classpath in my maven pom.xml
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
There is a directory under 'lib' which I also want to add to the classpath but it doesn't seem to pick it up.
Is there any way to do this?
If you want to add a directory to your Class-Path in your Manifest file, you can add something like this to your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>your_main_class</mainClass>
</manifest>
<manifestEntries>
<Class-Path>lib/myfolder/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
You cannot do it with jar plugin. Try assembly plugin, it is more flexible
Related
I have a customized jar that the application uses. Instead of installing jar in maven I want to make reference to it by defining absolute location for that jar in the manifest file. I am using the code shown below to update information in manifest file. However, I am not sure how can I reference to the jar location that uses absolute path like : D:/Shared_library/Test.jar . This might not be a good practice but I want to see if there is anything like that:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.ad.MainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
You can add it using <manifestEntries> tag.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Class-Path>file:///D:/Shared_library/Test.jar</Class-Path>
</manifestEntries>
<manifest>
<mainClass>org.ad.MainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I did mvn package and ran my file by doing java -jar target\output.jar
All the jar libraries specified in the dependency of pom.xml are not included. Do advice what's wrong below. Thanks!
Below is my pom.xml to allow jar file generation.
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.workspez.psg.letrikEtara.PlanetGroupLetrikEtara</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Try and compare/complete your declaration with the ones in "Including dependencies in a jar with Maven", like adding the executions section.
Or, if this is not working, consider the maven shade plugin, whic can achieve a simlar goal.
Got it working. This was missing:
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
To the following should work:
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.workspez.psg.letrikEtara.PlanetGroupLetrikEtara</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
When I build my Spring boot project, it creates an target folder and
target/classes also, but it doesn't create any META-INF. I have also included dependency -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
</manifestEntries>
</archive>
</configuration>
Two ways to do it.
Form the maven-jar-plugin documentation :
Please note that the following parameter has been completely removed
from the plugin configuration:
useDefaultManifestFile
If you need to define your own MANIFEST.MF file you can simply achieve
that via Maven Archiver configuration like in the following example:
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
where in you can place your MANIFEST.MF under src/main/resources/META-INF folder of your project. The command
mvn clean package
would build the project jar with the src/main/resources by default.
The notes at usage of the plugin states that
Starting with version 2.1, the maven-jar-plugin uses Maven Archiver
3.1.1. This means that it no longer creates the Specification and Implementation details in the manifest by default. If you want them
you have to say so explicitly in your plugin configuration.
Which can be done using:
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
I want to put jar into my generated jar file .
i want to include a new dependency (external.jar) for my executable jar file.the external.jar do not contain a main method.
Use jar cf jar-file input-file(s). I recommend reading http://www.skylit.com/javamethods/faqs/createjar.html , https://docs.oracle.com/javase/tutorial/deployment/jar/build.html and Java creating .jar file
If you are using mavan, you can add the next to pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
I am trying to find a way of putting version information in manifest file into JAR using Maven?
For WAR files I use the following in my POM.XML
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
and then I run "mv clean package"
How would you do this for a JAR.. Can you please give me details information on the changes and the commands... thanks
You can use maven-jar-plugin (the configuration is nearly the same as maven-war-plugin)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
</manifestEntries>
</archive>
</configuration>
...
</plugin>
Here the documentation of the plugin: https://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html
And all options: http://maven.apache.org/shared/maven-archiver/index.html