I have a project built using the netbeans IDE (Internally uses Ant to build if I am not mistaken)
The CI server we use is jenkins. I would like to add version info to the manifest for the jar that is produced.
How do I do that?
Assuming that your Jenkins build process somehow update the project version a possible solution is:
in nbproject\\build-impl.xml
add an entry for the manifest
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" ...
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Main-Class" value="${main.class}"/>
<!-- add this line below -->
<attribute name="Project-Version" value="${project.version}"/>
</manifest>
</target>
in nbproject\\project.properties
add the project version
project.version=0.0.1-SNAPSHOT
build
ant jar
output
$ unzip -p dist/CI-test.jar META-INF/MANIFEST.MF | grep Project
Project-Version: 0.0.1-SNAPSHOT
edit: Another solution using an environment variable.
in nbproject\\build-impl.xml
add an entry for the manifest using the environment variable PROJECT_VERSION
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" ...
<!-- enable access to environment variables -->
<property environment="env"/>
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Main-Class" value="${main.class}"/>
<!-- add this line below -->
<attribute name="Project-Version" value="${env.PROJECT_VERSION}"/>
</manifest>
</target>
build
# define the environment variable
# on Windows use: set PROJECT_VERSION=0.0.2-SNAPSHOT
PROJECT_VERSION=0.0.2-SNAPSHOT
ant jar
output
$ unzip -p dist/CI-test.jar META-INF/MANIFEST.MF | grep Project
Project-Version: 0.0.2-SNAPSHOT
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.