I have this code to add my classpath:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>ApuestaYa</mainClass>
</manifest>
<manifestEntries>
<Class-path>../lib/jcalendar.jar ../lib/eclipselink.jar ../lib/libforms-1.3.0.jar ../lib/Imagenes.jar ../lib/DriverPersistencia.jar ../lib/javax.persistence_2.0.3.v201010191057.jar</Class-path>
</manifestEntries>
</archive>
</configuration>
</plugin>
But I got this in my manifest.mf:
Manifest-Version: 1.0
Implementation-Title: Apuestaya
Implementation-Version: 0.9.0-SNAPSHOT
Implementation-Vendor-Id: um.tds.VictorMRuiz
Built-By: Celor
Build-Jdk: 1.7.0_09
Class-Path: ../lib/jcalendar.jar ../lib/eclipselink.jar ../lib/libform
s-1.3.0.jar ../lib/Imagenes.jar ../lib/DriverPersistencia.jar ../lib/
javax.persistence_2.0.3.v201010191057.jar
Created-By: Apache Maven 3.0.4
Main-Class: ApuestaYa
Archiver-Version: Plexus Archiver
As you can see, Maven put random blank spaces in the jar's routes.
For example: ../lib/libform s-1.3.0.Jar ... So, when I lunch mi jar I get an error because it can't find the jars. Any ideas?
A workaround
Use version 2.3.2 of maven-jar-plugin and change configuration of Class-path.
<Class-path><![CDATA[../lib/jcalendar.jar
../lib/eclipselink.jar
../lib/libforms-1.3.0.jar
../lib/Imagenes.jar
../lib/DriverPersistencia.jar
../lib/javax.persistence_2.0.3.v201010191057.jar]]></Class-path>
It will make your classpath multi line, just remember about spaces at start of each line.
According to Jar specification, manifest line can have at most 72 bytes.
Related
I am working on java project with Maven and Maven-jar-plugin
I have generated a classpath of dependencies for my jar file in MANIFEST.MF using maven jar plugin.
here is my plugin usage:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
<manifestSections>
<manifestSection>
<name>${project.name}</name>
<manifestEntries>
<git-branch>${git.branch}</git-branch>
<git-build-host>${git.build.host}</git-build-host>
<git-build-time>${git.build.time}</git-build-time>
<git-build-user-email>git.build.user.email</git-build-user-email>
<git-build-user-name>git.build.user.name</git-build-user-name>
<git-build-version>${git.build.version}</git-build-version>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin
and the generated classpath is like this:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Build-Time: 2020-01-23T13:34:14Z
Class-Path: org/apache/logging/log4j/log4j-api-2.6.2.jar
org/apache/logging/log4j/log4j-core-2.6.2.jar
org/apache/commons/commons-configuration2-2.2.jar org/apache/commons/commons-lang3-3.6.jar
commons-loggin g/commons-logging-1.2.jar
commons-beanutils/commons-beanutils-1.9.3.jar
commons-collections/commons-collections-3.2.2.jar
Created-By: Apache Maven 3.6.2
Build-Jdk: 1.8.0_181
Name: service_utils
git-commit-id-abbrev: d78e66c
but I do need to generate my classpath with relative path and not path throughthe lib or WEB-INF.
I am looking to have something like this:
Manifest-Version: 1.0
Class-Path:
../../../org/hibernate/hibernate-core/5.1.0.Final/hibernate-core-5.1.0.Final.jar ../artifacts/org/hibernate/hibernate-core/5.1.0.Final/hibernate-core-5.1.0.Final.jar ../../../org/hibernate/common/hibernate-commons-annotations/5.0.1.Final/hibernate-commons-annotations-.0.1.Final.jar
../artifacts/org/hibernate/common/hibernat e-commons-annotations/5.0.1.Final/hibernate-commons-annotations-5.0.1 .Final.jar
../../org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar
../artifacts/org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar
../../../com/mchange/c3p0/ 0.9.2.1/c3p0-0.9.2.1.jar
I have searched and studied so many of StackOverflow's questions regarding having manifest file in a jar file with their relative path classpath, I have seen options for gradle but I am looking for maven solution and better if I can perform this with maven jar plugin.
I found a way to get the relative address, but the depth is hardcoded and it will not be a perfect solution for multimodule projects.
<manifest>
<addClasspath>true</addClasspath>
<mainClass>My.Main</mainClass>
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>../../../$${artifact.groupIdPath}/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension} ../artifacts/$${artifact.groupIdPath}/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>
</manifest>
I´m trying to update a manifest file adding a pair of new lines inside a classpath.
I have something like this in my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Class-Path>./ttttttttttttttt/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
The result of this change is the next one:
Manifest-Version: 1.0
Implementation-Title: server
Implementation-Version: 0.1.0-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: vcima
Implementation-Vendor-Id: es.solution.ok
Class-Path: **../ttttttttttttttt/** configuration-0.1.0-SNAPSHOT.jar
tip-0.1.0-SNAPSHOT.jar quartz-2.2.1.jar c3p0-0.9.1.1.jar quartz-
jobs-2.2.1.jar
company: My company
Created-By: Apache Maven 3.3.3
Build-Jdk: 1.8.0_111
Main-Class: es.example.srv.ServerRunner
That its right but i need that the new line was added at the end of the classpath for several reasons: order of the libraries is important in this case...
I´m looking the workaround for something like this:
Manifest-Version: 1.0
Implementation-Title: server
Implementation-Version: 0.1.0-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: vcima
Implementation-Vendor-Id: es.solution.ok
Class-Path: configuration-0.1.0-SNAPSHOT.jar
tip-0.1.0-SNAPSHOT.jar quartz-2.2.1.jar c3p0-0.9.1.1.jar quartz-
jobs-2.2.1.jar **../ttttttttttttttt/**
company: My company
Created-By: Apache Maven 3.3.3
Build-Jdk: 1.8.0_111
Main-Class: es.example.srv.ServerRunner
Could anyone help me?.
Best regards!
I am using Jenkins ver. 1.521 and standard maven plugin (ver 1.519) to build maven2 projects.
In manifest I can see entries I didn't configure in any of pom files:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: jenkins
Build-Jdk: 1.6.0_45
Hudson-Build-Number: ...
Hudson-Project: ...
Hudson-Version: ...
Jenkins-Build-Number: ..
Jenkins-Project: ...
Jenkins-Version: ...
Where can I configure these entries?
I don't know of any default behavior like that. Typically this is configured in the build section of your pom. Are you sure it isn't coming from an ancestor pom somewhere?
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Job>${JOB_NAME}</Build-Job>
<Build-Id>${BUILD_ID}</Build-Id>
<Build-Number>${BUILD_NUMBER}</Build-Number>
<Build-Repository-Rev>${SVN_REVISION}</Build-Repository-Rev>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
In this example the child XML elements of manifestEntries are created based on the element names. Their can come from Maven properties, e.g. maven.build.timestamp, or environment variables, e.g. JOB_NAME. The environment variables JOB_NAME, BUILD_ID, etc are set by Jenkins when it executes the job.
Actually, I have found them hardcoded in source of maven plugin for jenkins, which is a sad thing.
I'd like to add an Implementation-Version line to manifest in my warfile.with implementation version as projectname_mmddyyy.version.How can configure this in maven?
See Maven Archiver for reference. The configuration should go like this:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
...
</archive>
</configuration>
My jar is not running, I can tell it tries to run as the log4j file manage to create the log folder but then nothing happens and the log is in blank.
My problem is I have the jar file in a folder called bin and the libraries in a folder called lib
I'm triying this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${staging.dir}/bin</outputDirectory>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>com.Main</mainClass>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
and
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${staging.dir}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
I also tried with maven-assembly-plugin, but it packs everything on the jar and I really need to have the folders bin and lib
What do I need to setup to make it work correctly?
EDIT: META-INF file
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: me
Build-Jdk: 1.6.0_26
Main-Class: com.Main
Class-Path: ../lib/ojdbc6-11.2.0.jar ../lib/sqljdbc4-4.2.0.jar ../lib/
mysql-connector-java-5.1.17.jar ../lib/hibernate-core-3.6.5.Final.jar
../lib/antlr-2.7.6.jar ../lib/commons-collections-3.1.jar ../lib/dom
4j-1.6.1.jar ../lib/hibernate-commons-annotations-3.2.0.Final.jar ../
lib/hibernate-jpa-2.0-api-1.0.0.Final.jar ../lib/jta-1.1.jar ../lib/s
lf4j-api-1.6.1.jar ../lib/hibernate-entitymanager-3.6.5.Final.jar ../
lib/cglib-2.2.jar ../lib/asm-3.1.jar ../lib/javassist-3.12.0.GA.jar .
./lib/slf4j-log4j12-1.6.1.jar ../lib/log4j-1.2.16.jar ../lib/commons-
codec-1.5.jar ../lib/lablib-checkboxtree-3.3-20110114.141734-3.jar
SOLUTION
turns out the META-INF file is incorrect. The reason is that maven-archiver-plugin renames SNAPSHOT libraries with a timestamp as default behaviour
to override that use this, as instructed by the Maven Archiver doc:
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<mainClass>com.Main</mainClass>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
other than that, I hope people find useful the maven code at the start because it does work, just beware the SNAPSHOTS in your projects
The above all seems OK. Here are some things/questions you may want to try/confirm/answer:
Are you running this from command line? I.e. using java -jar <your.jar> or are you starting it e.g. by double-clicking the file, etc.? If not, try running it from the command line to see what happens
Try using mvn exec:java to see if that starts your app (maven-)regularly. See http://mojo.codehaus.org/exec-maven-plugin/usage.html if you are not familiar with exec plugin
Can you use regular Java System.out.println instead of logging to confirm that it actually starts? Having a zero-size log might be a logging configuration issue
I see you have some DB libraries above. Can you put some println (or better logging, but only after you confirm your logging actually works) statements around basic initialization, to confirm that you are not just stalling there (provided that's what's happening - you don't mention any exceptions or other issues in specific)
A lot depends on the actual application code, but hope some of the above might help you pinpoint the issue.
As a side note, is your main class really com.Main? If yes, may I suggest to change that to something more appropriate - e.g. com.yourdomain.yourapp.Main or something along these lines. Not that this will change the above result, just a stylistic comment.