Jenkins maven plugin alters manifest - maven

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.

Related

How to list dependencies with their relative path in class path of Manifest file of generated jar file using maven jar plugin?

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>

Sharing variables with child maven projects

I have a parent pom.xml which builds a series of modules. As part of the parent pom.xml I read a configuration and put a number of variables into the build environment:
BUILD_DATE=2014/07/24 15\:37\:06
BUILD_NUMBER=78
VERSION=GGY1.6
I wish to place this information into the manifest jar file. I am doing this as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<finalName>atf</finalName>
<archive>
<manifestEntries>
<Built-Date>${maven.build.timestamp}</Built-Date>
<Version>${VERSION}B${BUILD_NUMBER}</Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
I am not sure which section of the pom.xml this should go into. I have put it in the build phase, and in some modules this works out ok, but in others it comes out in the manifest as:
Created-By: Apache Maven 3.0.5
Built-Date: 28/07/2014-16:00
Version: ${VERSION}B${BUILD_NUMBER}
Archiver-Version: Plexus Archiver
Is there a specific place in the pom.xml I need to put the maven-jar-plugin in order for it to pick up variables created by the parent?
I think the missing piece in the modules pom.xml files was this:
<plugin><groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
</plugin>
Any module pom which had this piece added, populated the manifest correctly... along with the maven-jar-plugin snippet. It looks like both are needed in order to access the values set by the parent pom.xml

Error trying to adding arbitrary classpath in Manifest.mf

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.

How to add libs to Classpath in my manifest file via maven?

I using Maven 3 + hudson + artifacotory
I used the following
<artifactId>maven-war-plugin</artifactId> <addClasspath>true</addClasspath> <classpathPrefix>WEB-INF/lib/</classpathPrefix> </manifest>
and I got the result as.....
WEB-INF/lib/gwt-servlet-2.4.0.jar WEB-INF/lib/gwt-user-2.4
.0.jar WEB-INF/lib/validation-api-1.0.0.GA.jar WEB-INF/lib/validation
-api-1.0.0.GA-sources.jar WEB-INF/lib/log4j-1.2.16.jar WEB-INF/lib/co
mmons-lang-2.6.jar
I am find well and good.
My one more requirement is,
I need to add/append two more libs with the above manifest file. see below
/u01/app/TimesTen/tt1121/lib/orai18n.jar /u01/app/TimesTen/tt1121/lib/ttjdbc5.jar
So how can add/append this is to my Manifest, so that above 3 will be included?
maven war plugin as well as maven jar plugin use maven archiver which in turn allows you to specify your own manifest file. According to the documentation,
The content of your own manifest file will be merged with the entries
generated by Maven Archiver.
Cut/pasting the relevant pom snippet from the above link for ready reference
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
...
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
So you could add the additional entries in this custom MANIFEST.MF and use it in conjunction with the maven war plugin.

Maven executable jar with libraries on external path

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.

Resources