Since the latest java release (7u45), I'm getting tons of errors on third part jar libraries that my webstart application uses, due to newly required manifest attributes being missing:
Missing Application-Name: manifest attribute for: http://site/lib/jh.jar
Missing Permissions manifest attribute for: http://site/lib/jh.jar
Missing Codebase manifest attribute for: http://lib/jh.jar
So, I need to run a batch ant task to update the manifest files in each of the 30 or so required libraries before I can use them for distribution.
How can I do this in ant? (preferably without ant-contrib)
PS: I've already fixed all the other 7u45 update crap (code signing, JNLP attribs, etc).
Try something like this.
<for param="jarFile">
<fileset dir="${webapp.dir}">
<include name="*.jar"/>
</fileset>
<sequential>
<jar update="true" file="#{jarFile}">
<manifest>
<attribute name="Application-Name" value="ABCDEF"/>
<attribute name="Codebase" value="*"/>
<attribute name="Permissions" value="all-permissions"/>
</manifest>
</jar>
</sequential>
</for>
Related
I'm creating some runnable JARs (desktop JavaFX applications).
I have a fileset of the 3rd party JARs I'm including:
<fileset id="shared_lib" dir="${aux.debian.lib.dir}">
<include name="commons-lang3-3.4.jar"/>
<include name="commons-io-2.4.jar"/>
...
</fileset>
And I then use zipgroupfileset to include those in the final runnable JAR:
<jar destfile="myapp.jar" filesetmanifest="mergewithoutmain">
<zipgroupfileset refid="shared_lib"/>
<manifest>
<attribute name="Main-Class" value="mypackage.myapp"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="./classes" />
</jar>
When I then run ProGuard I get the following warnings multiple times (as each of the zipped JARs contain a LICENSE.txt and NOTICE.txt):
[proguard] Warning: can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [myapp.jar:META-INF/LICENSE.txt])
[proguard] Warning: can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [myapp.jar:META-INF/NOTICE.txt])
I've tried the various exclude options when defining the fileset, but they only exclude files from the fileset, not from within the include JARs.
Is there away to simply filter what gets zipped as part of the zipgroupfileset? Perhaps in ProGuard?
This is only a minor annoyance, as everything works with the warnings, but it's annoying me that something that I have a feeling should be simple is eluding me.
You can add duplicate="preserve" to your <jar> element, as described in the documentation:
duplicate
behavior when a duplicate file is found. Valid values are "add", "preserve", and "fail". The default value is "add".
I'm using Apache Ant to compile, jar and run a java project for school. I've run into a problem that I don't know how to include a single .txt file into my .jar, and then reference it as well in my java code.
Here is my compile and jar command in my build.xml.
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/BinaryTree.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="cs3345.MainLauncher"/>
</manifest>
</jar>
</target>
What command do I use to include a .txt file into my jar. I've seen a couple Stack Overflow questions about it already, notably
adding non-code resources to jar file using Ant
How can I include data text files in a jar using Ant?
But none of them really explained how to include a file. They just had commands that didn't really make sense to me. I've tried,
<jar destfile="build/jar/BinaryTree.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="cs3345.MainLauncher"/>
</manifest>
<fileset dir="src/resources" />
</jar>
But that didn't seem to help because I just don't understand Ant, I couldn't find documentation for it that actually explained why you do different things in ant.
My .txt file is in, src/resources.
The <jar> task tasks multiple filesets:
<jar destfile="build/jar/BinaryTree.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="cs3345.MainLauncher"/>
</manifest>
<fileset dir="src/resources" />
</jar>
The <manifest> task is a sub entity. It's very much like the <manifest> task. In your jar is a file called META-INF/MANIFEST.MF and this is adding another attribute to that jar. This particular attribute tells the Jar what is the main class which should launch when the jar is exeuted.
The <fileset dir="src/resources"/> is adding all the files that are found in theresources` directory. What if you only want to add a particular file? You can use selectors. For example:
<jar destfile="build/jar/BinaryTree.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="cs3345.MainLauncher"/>
</manifest>
<fileset dir="src/resources">
<include name="foo.txt"/>
</fileset>
</jar>
This time I'm not adding the entire resources directory tree. I'm just adding a single file called foo.txt into my jar file.
Use <copy>:
<target name="copy" depends="blablabla" description="Copies additional files">
<echo>Start Copying Files</echo>
<copy file="./src/resources/a.txt" overwrite="true" todir="build/classes/"/>
<echo>End Copying Files</echo>
</target>
As a side note
If we want to include some files under src folder, we can write under target something like:
There is nothing in the documentation that says, "you can only add .class files". The fileset tag should work. Perhaps it's putting the file in a place you're not looking. Run in verbose mode to figure out what it's doing with your .txt file. To control the destination, you should use the zipfileset tag.
But that didn't seem to help. My .txt file is in, src/resources.
You're going to have to elaborate on that. How didn't it help? Is the problem that the file was nested under the zip or didn't go in there or you got an error?
I have the following target in my build.xml:
<target name="-pre-compile">
<property file="build.properties"/>
<buildnumber file="build.version"/>
<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd HH:mm:ss"/>
</tstamp>
<manifest file="manifest.mf">
<attribute name="MAJOR" value="${version.major}"/>
<attribute name="MINOR" value="${version.minor}"/>
<attribute name="RELEASE" value="${release}"/>
<attribute name="BUILD" value="${build.number}"/>
<attribute name="BUILD-DATE" value="${timestamp}"/>
<attribute name="PROTOCOL" value="${protocol}"/>
<attribute name="APPCODE" value="${appcode}"/>
</manifest>
</target>
It works fine, opening manifest.mf after a Clean and Build within Netbeans shows all my extra attributes that I've added. However, when I open my jar file I see that it just contains the default stuff:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0-b147 (Oracle Corporation)
I had this working fine before when I had two packages in one project. The one package was all library stuff that I'm gonna be taking to other projects, so I decided to split it out into another project so I could build the library jar by itself. Now I have this problem. It occurs both when I compile the library on its own as well as my other project that depends on it.
I've fixed it by opening nbproject/project.properties and adding manifest.file=manifest.mf to the end. Simple as that.
check this answer here: Is it possible to add a custom manifest to a Java library compiled in Netbeans 6.7.1?
I had your same problem, adding this at the end of my build.xml solved the issue:
<target name="-post-jar">
<jar destfile="${dist.jar}" update="true">
<manifest>
<attribute name="Manifest-Version" value="1.0" />
<attribute name="Extension-Name" value="polpol" />
<attribute name="Class-Manager" value="org.nlogo.extensions.polpol.Manager" />
<attribute name="NetLogo-Extension-API-Version" value="5.0" />
</manifest>
</jar>
</target>
I happen to have encountered the same issues youre having here, and luckly enough have fixed it. Unfortunately I dont know what exactly caused the issue, and after comparing your code to mine, the only difference I see really is the name of the manifest file in your build.xml, and the event which triggers the task (I used pre init). I have all in capitals, and supplement the manifest version info with in the Version.txt file which is created in the dist directory -post-jar. You may just want to try to make
manifest file="manifest.mf"
read
manifest file="MANIFEST.MF"
Here is a copy of the important parts of my build.xml:
<property name="project.name" value="VOXManagement" />
<property name="version.num" value="1.1" />
<target name="-pre-init">
<tstamp>
<format property="NOW" pattern="yyyy-MM-dd HH:mm:ss z" />
</tstamp>
<manifest file="MANIFEST.MF">
<attribute name="Bundle-Name" value="${project.name}" />
<attribute name="Bundle-Version" value="${version.num}" />
<attribute name="Bundle-Date" value="${NOW}" />
<!--<attribute name="Bundle-Revision" value="${svna.version}" />-->
<attribute name="Implementation-Title" value="${project.name}" />
<attribute name="Implementation-Version" value="${version.num}" />
</manifest>
<echo file="Version.txt">V${version.num}</echo>
</target>
<target name="-post-jar">
<copy file="Version.txt" todir="dist" overwrite="true"/>
<delete file="dist/README.TXT"/>
</target>
You need to use the "update mode".
<manifest file="${manifest.file}" mode="update">
As Thihara already asked, you may have a task that builds the jar?
are you having manifest="MANIFEST.MF" in your create jar(or something similary ) tag/task?
<target name="jar">
<jar manifest="path-to/MANIFEST.MF" basedir="base dir" destfile="outJarfileName">
</jar>
</target>
While Creating Jars,Wars,Ears a common issue in MANIFEST.MF is
"Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_40-b43 (Oracle Corporation)"
If you want to Ignore Ant-Version Number and Created by use filesetmanifest="mergewithoutmain" option.
<jar destfile="MyJar.jar" basedir="./bin" filesetmanifest="mergewithoutmain" manifest="./src/META-INF/MANIFEST.MF" update="true" >
In Netbeans 7.3.X
for .war
in the build.xml Use
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF">...</manifest>
My Question is: How am i able to put files in a subdirectory into my jar via ant? Right now my Code is:
<jar destfile="${dist.dir}\wo42.jar" basedir="bin">
<manifest>
<attribute name="Main-Class" value="org.alternativedev.wo42.App" />
<attribute name="Class-Path" value="lib" />
</manifest>
<zipgroupfileset dir="lib/." excludes="natives/*" />
<fileset dir="data/." includes="." />
It creates a structure like
ROOT-Jar
-org
--bla
-filefromdata1
-filefromdata2
But it should be
ROOT-Jar
-org
--bla
-data
--filefromdata1
--filefromdata2
Do You know what I mean?
Greetings, BigTeddy
Change the last line to
<fileset dir="." includes="data/**" />
No need to copy files around.
An alternative way (which is useful if you want to have the directory in the archive to have a different name) would be
<zipfileset dir="data" includes="." prefix="folder-name-in-jar"/>
First, you create the file structure you need and copy to it all the files required. Then you run jar command on the resulting root directory.
In order to copy files you can use the ANT copy task
For example:
<copy todir="../dest/dir">
<fileset dir="." includes="data/**/*.java">
</fileset>
More on how to pack jar (basics) here
I'm trying to compile a runnable jar-file for a project that makes use of hibernate. I'm trying to construct an ant build.xml file to streamline my build process, but I'm having troubles with the inclusion of the hibernate3.jar inside the final jar-file.
If I run the ant script I manage to include all my library jars, and they are put in the final jar-file's root. When I run the jar-file I get a
java.lang.NoClassDefFoundError: org/hibernate/Session
error. If I make use of the built-in export to jar in Eclipse, it works only if I choose "extract required libraries into jar". But that bloats the jar, and includes too much of my project (i.e. unit tests).
Below is my generated manifest:
Manifest-Version: 1.0
Main-Class: main.ServerImpl
Class-Path: ./ antlr-2.7.6.jar commons-collections-3.1.jar dom4j-1.6.1.jar
hibernate3.jar javassist-3.9.0.GA.jar jta-1.1.jar slf4j-api-1.5.11.jar
slf4j-simple-1.5.11.jar mysql-connector-java-5.1.12-bin.jar rmiio-2.0.2.jar
commons-logging-1.1.1.jar
And the part of the build.xml looks like this:
<target name="dist" depends="compile" description="Generates the Distribution Jar(s)">
<mkdir dir="${dist.dir}" />
<jar destfile="${dist.dir}/${dist.file.name}.jar" basedir="${build.prod.dir}" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="${main.class}" />
<attribute name="Class-Path" value="./ ${manifest.classpath} " />
<attribute name="Implementation-Title" value="${app.name}" />
<attribute name="Implementation-Version" value="${app.version}" />
<attribute name="Implementation-Vendor" value="${app.vendor}" />
</manifest>
<zipfileset refid="hibernatefiles" />
<zipfileset refid="slf4jfiles" />
<zipfileset refid="mysqlfiles" />
<zipfileset refid="commonsloggingfiles" />
<zipfileset refid="rmiiofiles" />
</jar>
</target>
The refids' for the zipfilesets point to the directories in a library directory lib in the root of the project. The manifest.classpath-variable takes the classpath of all those library jar-files, and flattens them with pathconvert and mapper.
I've also tried to set the manifest classpath to ".", "./" and only the library jar, but to no difference at all. I'm hoping there's a simple remedy to my problems...
Since you can't specify jar-inside-jar in your classpath, this way won't work.
You need either to jar only your code and then zip your jar with libs jars and launch script, like
#!/bin/sh
java -cp ./hibernate.jar:./mycode.jar... my.Main
(this what most people do), or you may unpack all your lib jars to the same dir which contains your compiled classes and then jar result dir back to single jar file (this what maven jar-with-dependencies packaging do).