I am using netbeans to create an app.
When I export in the dist file everything's working correctly, when I am exporting for store (to include the libraries in the .jar), netbeans exports an earlier program version. Oh and yes, I have tried restarting netbeans didn't really do anything.
This is actually the first time I encountered this issue.
And yes I have saved the project.
Is this a netbeans issue or am I doing something wrong?
this is the image of what I'm doing:
this is the build.xml code
<?xml version="1.0" encoding="UTF-8"?>
<project name="GalaxyChromaY2_BoilerPlate" default="default" basedir=".">
<description>Builds, tests, and runs the project JavaApplication2.</description>
<import file="nbproject/build-impl.xml"/>
<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="GalaxyChromaY2"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
</project>
For some reason netbeans was exporting an older version of the project so I copied the whole project file deleted the old one and tried to export again.
This time everything worked as it should.
Related
I have a problem with Ant Build Tool.
First, below you can see my project structure:
and the content of my build.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<project name="addonGenerator" default="main" basedir=".">
<property name="projectName" value="addonGenerator"/>
<property name="src.dir" location="src"/>
<property name="build.dir" location="bin"/>
<property name="dist.dir" location="dist"/>
<target name="compile" description="compile the source ">
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath>
<pathelement path="lib/velocity-1.7.jar"/>
<pathelement path="lib/log4j-1.2.16.jar"/>
</classpath>
</javac>
</target>
<target name="dist" description="package, output to JAR">
<mkdir dir="${dist.dir}"/>
<jar jarfile="${dist.dir}/${projectName}.jar" basedir="${build.dir}">
<zipgroupfileset dir="lib" includes="velocity-1.7.jar" />
<zipgroupfileset dir="lib" includes="log4j-1.2.16.jar" />
<manifest>
<attribute name="${projectName}" value="main"/>
<attribute name="Main-Class" value="main.java.AddonGenerator"/>
</manifest>
</jar>
</target>
<target name="clean" description="clean up">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="main" depends="clean, compile, dist"/>
</project>
I don't know how setup the Ant build.xml to build and run my project with external libraries and the java property file generator.properties
To include your generator.properties file in the .jar file, add your resources directory when building the .jar:
<jar jarfile="${dist.dir}/${projectName}.jar" basedir="${build.dir}">
<fileset dir="src/main/java/resources"/>
Since you are currently building a “fat jar” (by directly including the contents of your library .jars in your application .jar), you can run by simply invoking your .jar file. Such a target obviously requires the .jar file to be built, so it makes sense to depend on the "dist" target:
<target name="run" depends="dist">
<java jar="${dist.dir}/${projectName}.jar"/>
</target>
On another note, I don’t think you want to pass src as your source directory, unless your classes actually declare themselves with ‘package main.java;’ (which they shouldn’t). You should pass the actual root of your packages to the javac task:
<property name="src.dir" location="src/main/java"/>
You should also make the "dist" target depend on "compile", since, well, it depends on having compiled classes available.
I also would suggest that your default target, "main", avoid calling the "clean" target. You should not clean before every single build; that defeats one of the most useful benefits of Ant, namely the ability to update only the things that need to be updated. You should only clean when you need to, with a command like ant clean compile or simply ant clean.
Note that once "dist" depends on "compile", and once "main" no longer calls "clean", you can simply remove the "main" target and change your project’s default target to "dist". When you think about it, this makes sense: the default action is to build and package the application.
I have a openCV project in eclipse. Now I am trying to make it runnable Jar but not able to launch it , once trying to run the jar.
I tried following -
https://groups.google.com/forum/#!topic/javacv/ziqKIb7PgYk
but I couldn't understand properly. Can anyone explain the proper way to do the needful.
in my System , OpenCV is installed. Once I try to run the project from
eclipse , everything works fine . but when I try to do the same from
runnabelJar it doesn't. The problem I found it that I didn't include
.dll files , so how should I do it.
I finally got the solution. Yes we can easily make Runnable jars from eclipse while using javaCV , no need for ant or maven build.
No Need to set the class path with OpenCV, which you are only using javaCV and no intention for jni build.
Create a Java Project.
Copy all the jars.You can avoid x86 or linux or non required jars as
well.
Find the jre version , if 32 bit , get the path of OpenCV 32 bits
libraries else 64 bits. You can place those dlls any where in the
system.. No need to place it any specific path.
Go to OpenCV jar , expand it , click on Native Library Location ,
edit and browse the path
Thats it , job Done , now make Runnable jar or anything , it will work like charm.
Once you provide your runnable jar to any user, then either user's openCV path should be set in the class path or you provide the dlls , and you Load the library in any static block.
Building a jar with ANT (for javacv 0.9):
install opencv (and/or ffmpeg)
download javacv from https://github.com/bytedeco/javacv
Create a Java Project and create the directories 'lib', 'lib32' and 'lib64' in the root
and add the x64 jars from javacv to lib64 - same for lib32 and the others without bit-version in lib
Add the following jars to the buildpaht of your project (Add External JARs...) and set the Native library paths for opencv (and/or ffmpeg)
Sample Test class
public class Main {
public static void main(String[] args) throws Exception, IOException {
OpenCVFrameGrabber frameGrabber = new OpenCVFrameGrabber(new File(".\\tmp_files\\small.mp4"));
frameGrabber.start();
IplImage origImg = frameGrabber.grab();
//create canvas frame named 'Demo'
final CanvasFrame canvas = new CanvasFrame("Demo");
//Show image in canvas frame
canvas.showImage(origImg);
//This will close canvas frame on exit
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
}
ANT -script
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="main" name="Main">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<property name="build.dir" value="bin"/>
<property name="src.dir" value="src"/>
<property name="lib.dir" value="lib"/>
<property name="lib32.dir" value="lib32"/>
<property name="lib64.dir" value="lib64"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="jar.file" value="${jar.dir}/buildOpenCvTest32_64.jar"/>
<property name="manifest.file" value="${jar.dir}/MANIFEST.MF"/>
<property name="main.class" value="test.Main"/>
<path id="external.jars">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<fileset dir="${libV.dir}" includes="**/*.jar"/>
</path>
<path id="project.classpath">
<pathelement location="${src.dir}"/>
<path refid="external.jars" />
</path>
<target name="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${jar.dir}"/>
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="cleanall" depends="clean"/>
<target name="build" depends="init">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}" classpathref="project.classpath">
<src path="${src.dir}"/>
</javac>
</target>
<target name="build-jar" depends="build">
<delete file="${jar.file}" />
<delete file="${manifest.file}" />
<manifest file="${manifest.file}" >
<attribute name="built-by" value="${user.name}" />
<attribute name="Main-Class" value="${main.class}" />
</manifest>
<jar destfile="${jar.file}"
basedir="${build.dir}"
manifest="${manifest.file}">
<fileset dir="${classes.dir}" includes="**/*.class" />
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar" />
<zipgroupfileset dir="${lib32.dir}" includes="**/*.jar" />
<zipgroupfileset dir="${lib64.dir}" includes="**/*.jar" />
</jar>
</target>
<target name="main" depends="build-jar">
<description>Main target</description>
</target>
</project>
Run ANT - the jar should run on every 32 and 64bit Windows system. same should work for ffmpeg library and for unix systems
I have an Ant build.xml file that works just fine on the command line: it compiles, builds the JAR, and I am able to execute the main method from the JAR just fine. The build.xml file references several thirdparty libraries that are scattered here and there. When building the JAR, the script doesn't include all the thirdparty libraries into the JAR itself. Instead, it puts their path into the JAR's manifest. This helps to keep my JAR slim and tidy.
I'd like to be able to edit and debug my project in Eclipse, but I can't find an easy way to do so. I can have my project use the Ant file to build the project, and that seems to work. However, Eclipse is having trouble finding the thirdparty libaries, and thus Eclipse is having two problems:
it shows (in the text editor) lots of compile errors, because
lots of classes are undefined, and
it can't execute the JAR.
I can solve both of the above problems by specifying by hand, in two difference places (i.e., the build path via Properties->Java Build Path->Libraries, and the execution classpath via Run Configurations->Classpath), all the third party libraries. But it seems like I shouldn't have to do this manually, since all the third party libraries are already listed in my JAR's manifest. What am I doing wrong?
Here's my build.xml file:
<!-- Set global properties for this build -->
<property name="src" location="./src" />
<property name="build" location="./build"/>
<property name="dist" location="./dist"/>
<property name="logs" location="./logs"/>
<property name="docs" location="./docs"/>
<property name="jar" location="${dist}/dynamic_analyzer.jar"/>
<property name="lib" location="../../thirdparty/lib"/>
<property name="hive-util" location="../../hive-utils/dist"/>
<property name="hpdb" location="../../hive-db/hpdb/dist"/>
<property name="static" location="../../hive-backend/static_analyzer/dist"/>
<property name="mainclass" value="com.datawarellc.main.DynamicMain"/>
<path id="dep.runtime">
<fileset dir="${lib}" includes="**/*.jar"/>
<fileset dir="${hive-util}" includes="**/*.jar"/>
<fileset dir="${hpdb}" includes="**/*.jar"/>
<fileset dir="${static}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${docs}"/>
<delete dir="${logs}"/>
</target>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${dist}"/>
<mkdir dir="${logs}"/>
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}" debug="on" includeantruntime="false">
<classpath refid="dep.runtime" />
</javac>
<!-- Debug output of classpath -->
<property name="myclasspath" refid="dep.runtime"/>
<echo message="Classpath = ${myclasspath}"/>
</target>
<target name="jar" depends="compile">
<!-- Put the classpath in the manifest -->
<manifestclasspath property="manifest_cp" jarfile="${jar}" maxParentLevels="10">
<classpath refid="dep.runtime" />
</manifestclasspath>
<jar jarfile="${jar}" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="${mainclass}"/>
<attribute name="Class-Path" value="${manifest_cp}"/>
</manifest>
<zipfileset dir="${src}" includes="**/*.xml" />
</jar>
</target>
You can see that I have third-party libraries in several directories (${lib}, ${hive-util}, ${hpdb}, and ${static}). I use these to create a path called dep.runtime. I then include dep.runtime in the manifest when building my jar. How can I get Eclipse to use the same dep.runtime for the build path and the classpath when executing?
An alternative to perl is to use an embedded groovy task:
<project name="demo" default="eclipse-files">
<property name="src.dir" location="src"/>
<property name="classes.dir" location="build/classes"/>
<path id="dep.runtime">
<fileset dir="${lib}" includes="**/*.jar"/>
<fileset dir="${hive-util}" includes="**/*.jar"/>
<fileset dir="${hpdb}" includes="**/*.jar"/>
<fileset dir="${static}" includes="**/*.jar"/>
</path>
<target name="bootstrap">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/groovy-all.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.4/groovy-all-2.1.4.jar"/>
</target>
<target name="eclipse-files">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<groovy>
import groovy.xml.MarkupBuilder
project.log "Creating .classpath"
new File(".classpath").withWriter { writer ->
def xml = new MarkupBuilder(writer)
xml.classpath() {
classpathentry(kind:"src", path:properties["src.dir"])
classpathentry(kind:"output", path:properties["classes.dir"])
classpathentry(kind:"con", path:"org.eclipse.jdt.launching.JRE_CONTAINER")
project.references."dep.runtime".each {
classpathentry(kind:"lib", path:it)
}
}
}
</groovy>
</target>
<target name="clean">
<delete file=".classpath"/>
</target>
</project>
Notes:
The bootstrap target will download the 3rd party groovy jar (No dependency on perl)
Groovy can access the "dep.runtime" ANT path directly and iterate over its contents
Groovy has excellent support for writing XML files.
The following answer is similar and additionally generates the Eclipse .project file.
Using Apache Ivy with netbeans
I came up with the following workaround, inspired by the link provided by #leeand00.
First, I wrote a simple Perl script (called genClasspath.pl) that generates the .classpath file that Eclipse uses.
#!/usr/bin/perl
use strict;
if (#ARGV != 2) {
print STDERR "Usage: $0 OUTFILE CLASSPATHSTRING\n";
print STDERR "e.g., $0 .classpath path1:path2:path3\n";
exit 1;
}
my $OUTFILE = $ARGV[0];
my $CLASSPATHSTRING = $ARGV[1];
open my $out_fh, '>', $OUTFILE or die "Couldn't open output file: $!";
print $out_fh q{<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="build"/>
};
my #libs = split(":", $CLASSPATHSTRING);
foreach my $thisLib (#libs){
print $out_fh " <classpathentry kind=\"lib\" path=\"$thisLib\"/>\n";
}
print $out_fh "</classpath>\n";
Then, I have my build.xml file call this script with the content of dep.runtime:
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}" debug="on" includeantruntime="false">
<classpath refid="dep.runtime" />
</javac>
<property name="myclasspath" refid="dep.runtime"/>
<exec dir="." executable="../../scripts/genClasspath.pl" os="Linux">
<arg value=".classpath"/>
<arg value="${myclasspath}"/>
</exec>
</target>
The only catch is that I need to run Ant on the command line at least once before I open the project in Eclipse. But when I do, Eclipse is able to compile and execute my project just fine, since the classpath is exactly the same as Ant's.
When I run "clean and build" the .jar file that is being created only runs if the lib folder is at the same folder of the .jar file.
So if I move the jar file to the desktop and leave the lib folder in the dist folder, the jar file will give me an exception.
How can I deal with this problem?
I solved this by creating just one jar file with all libraries inside, adding the following to my build.xml file in NetBeans:
<target name="-post-jar">
<jar jarfile="dist/Combined-dist.jar">
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
<zipfileset src="lib/commons-io-1.4.jar" excludes="META-INF/*" />
<zipfileset src="lib/ninja-utils-3.2.jar" excludes="META-INF/*" />
<zipfileset src="lib/unicorn-1.0.jar" excludes="META-INF/*" />
<manifest>
<attribute name="Main-Class" value="com.example.mypackage.Main"/>
</manifest>
</jar>
</target>
This creates a jar file (Combined-dist.jar) which is the combination of the dist jar and the specified library jars (in this case, commons-io-1.4.jar,ninja-utils-3.2.jar and unicorn-1.0.jar). You have to be sure to specify your Main Class package for the new jar file or it won't run when you try to open it.
If you copy your jars into the source code directory, they will be in your final jar. Nevetheless, I am not sure if this will work 100% of the time.
There is a great post at java-forum that states the following:
Except for a select few circumstances, what works best for me is to
simply merge the files manually. A .jar is basically a .zip with
organized contents, and you can open them in almost any .zip capable
archive program (I just use gnome's standard archiver, File Roller,
and it works great). Backup your jar file and open it in the archiver
of your choice, and do the same for each library jar in the library
directory. Drag and drop the working folders (IE, everything EXCEPT
the META-INF Directory) from each library into your jar's root path
(alongside your META-INF and your app's root package). Now drag the
META-INF/MANIFEST.MF file from your jar to your Desktop or any other
folder. Open it, and erase the Class-Path and X-COMMENT lines. Don't
forget to leave a blank newline at the end of the file! Save the new
manifest file and drag it back to your jar's META-INF directory,
overwriting the old one. Test the jar.
That's really easy to package every dependent library (*.jar) into one single myProject.jar.
Just follow these steps and you will finally pack every dependent library into single jar. If you are using NetBeans then you can follow exactly or else you need to find your build.xml file in project files.
Follow these steps to edit build.xml
1) Click on Files tab on the left side of the project panel in NetBeans.
2) Double click on the build.xml file and add these lines in it just before </project> line
<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="myProject"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
3) Change value in second line of the code as per your project name which is
<property name="store.jar.name" value="myProject"/> //<---Just value not name
4) Save it and right click on build.xml and choose Run Target and then Other Targets and finally click on Package-for-store
5) And here you done. Now you can go and check just like dist folder there will be a store folder which will be containing your final complete jar including all of your dependent libraries. Now whenever you want to change / add more libraries or so, just follow step 4.
Picture for step 4
You could use Apache Ant since version 1.7 for build the JAR with the required libraries in only one file. You could have a configuration file as follows:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="buildJar">
<target name="buildJar">
<!-- Name of jar -->
<jar destfile="C:/MyJar.jar" filesetmanifest="mergewithoutmain">
<manifest>
<!-- Your class with the main method -->
<attribute name="Main-Class" value="myPackage.MyClass"/>
<!-- Path in the jar -->
<attribute name="Class-Path" value="."/>
</manifest>
<!-- Dir of compiled class -->
<fileset dir="C:/NetBeansProjects/MyProject/bin"/>
<!-- Include required jars -->
<zipfileset excludes="META-INF/*.SF"
src="C:/NetBeansProjects/MyProject/lib/library1.jar"/>
<zipfileset excludes="META-INF/*.SF"
src="C:/NetBeansProjects/MyProject/lib/library2.jar"/>
</jar>
</target>
</project>
In Netbeans, place the XML file in your project and run it with the context menu.
See more in Apache Ant User Manual.
If you are going to distribute your app to another pc
You just zip .jar along with lib folder.
If want to run your app from any place in your pc
Take in cosideration Maven way of doing this - create local repository eg. C:\libs where your libraries would exist and .jar could accesses them later from any place in your pc.
Or you could just use Maven. There is a discussion on distributing application with all dependencies (libraries): Java: How do I build standalone distributions of Maven-based projects?.
Copy that jar file to:
C:\Program Files\Java\jdk\jre\lib\ext
and
C:\Program Files\Java\jre\lib\ext
You should be able to use it in Netbeans and in your manual imports, just like standard imports.
I have found maybe the easiest solution for this problem here. You just need to copy the next code snippet at the end of the build.xml file in your project folder.
<target name="-post-jar">
<!-- Change the value to the name of the final jar without .jar -->
<property name="store.jar.name" value="MyJarName"/>
<!-- don't edit below this line -->
<property name="store.dir" value="dist"/>
<property name="temp.dir" value="temp"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${temp.dir}"/>
<mkdir dir="${temp.dir}"/>
<jar destfile="${temp.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<delete dir="${store.dir}"/>
<zip destfile="${store.jar}">
<zipfileset src="${temp.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete dir="${temp.dir}"/>
</target>
Go to the build.xml in the root of your project and add the code right before </project> tag at the end.
Now change the value of the first propertiy field as commented and save the changes.
From now on, each time you Clean & Build your project, the full jar with dependencies will be generated in the project dist folder
This is what worked for me:
I built in excel export functionality into my project. The 2 external .jars I used for this purpose was jxl.jar end sx.jar
Unpack these 2 jars into a folder(java classes) using 7-Zip without any META files. Unpack your project jar into the same folder including the META file.
Re-Pack the whole java classes folder using JARMaker to recreate your Project .jar in its original distribution folder ... and there you go ... full excel functionality.
user1016588's solution works for me. There's one typo: this line should be
zipfileset src="dist/lib/commons-io-1.4.jar" excludes="META-INF/*"
Try this - in the Netbeans IDE:
Go to Tools --> Libraries
In the dialog box, on the bottom left click "New Library", give a name
On the right side, click on "Add JAR/Folder"
Click OK on the bottom right
Re-start the IDE and check.
Follow these:-
1. Right click on project opened in netbeans editor
2. select properties
3. choose libraries
4. add jar
5. click ok
You can also use this (when the libraries are not in "dist/lib"), tested with NetBeans and ant-contrib:
<target name="-post-jar">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<!-- Path to ant-contrib -->
<pathelement location="../../Libs/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- Change the value to the name of the final jar without .jar -->
<property name="store.jar.name" value="${application.title}"/>
<!-- don't edit below this line -->
<property name="store.dir" value="dist"/>
<property name="temp.dir" value="temp"/>
<property name="temp.libs.dir" value="temp/libs"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<fileset id="store.jars.absolute" dir="${store.dir}" includes="*.jar"/>
<pathconvert property="store.jars.relative" refid="store.jars.absolute" dirsep="/">
<map from="${basedir}/" to=""/>
</pathconvert>
<for list="${store.jars.relative}" param="item">
<sequential>
<echo message="Adding #{item} into single JAR at ${store.jar}"/>
</sequential>
</for>
<delete dir="${temp.dir}"/>
<mkdir dir="${temp.dir}"/>
<for list="${javac.classpath}" param="item" delimiter=":">
<sequential>
<echo message="Adding #{item} into single JAR at ${store.jar}"/>
<copy file="#{item}" todir="${temp.libs.dir}" overwrite="true" />
</sequential>
</for>
<jar destfile="${temp.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="${store.dir}" includes="*.jar"/>
<zipgroupfileset dir="${temp.libs.dir}" includes="*.*"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<delete dir="${store.dir}"/>
<zip destfile="${store.jar}">
<zipfileset src="${temp.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete dir="${temp.dir}"/>
</target>
I have a custom MANIFEST.MF in my java-project in Eclipse.
When exporting the project to a jar, I choose
Use existing manifest from workspace
Extracting the .jar shows that eclipse generated its own manifest.
My manifest:
Manifest-Version: 1.0
Main-Class: de.somehow.tagPDF.Main
Class-Path: lib/iText-5.0.2.jar;lib/jxl.jar;lib/jai_codec.jar;lib/jai_core.jar
How can I fix this?
You can make use of a build.xml to build the jar file for you.
Then you just run the build.xml as a Ant task.
See
If you want the build.xml to run automatically every time you build your Eclipse project, you can add it to the Builders list.
See
Below is a sample build.xml where a custom manifest is used:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="Example" default="run_build">
<property name="guiJar" value="../../Library/<jar-name>.jar"></property>
<target name="run_build" depends="delete_old_jar,create_dirs,create_manifest,copy_all_class_files,create_jar,delete_temp_dirs">
</target>
<target name="delete_old_jar">
<delete file="${guiJar}">
</delete>
</target>
<target name="create_dirs">
<mkdir dir="jar_temp" />
<mkdir dir="jar_temp/META-INF" />
</target>
<target name="delete_temp_dirs">
<delete dir="jar_temp">
</delete>
</target>
<target name="create_manifest">
<manifest file="jar_temp/META-INF/MANIFEST.MF">
<attribute name="Manifest-Version" value="1.0" />
<attribute name="Version" value="1.0.0" />
<attribute name="Company" value="Value" />
<attribute name="Project" value="Value" />
<attribute name="Java-Version" value="${java.version}" />
<attribute name="Class-Path" value="test.jar" />
<attribute name="Main-Class" value="com.Main" />
</manifest>
</target>
<target name="create_jar">
<jar destfile="${guiJar}" manifest="jar_temp/META-INF/MANIFEST.MF" basedir="jar_temp">
</jar>
</target>
<target name="copy_all_class_files">
<copy todir="jar_temp">
<fileset dir="classes">
<include name="*/**" />
</fileset>
</copy>
</target>
</project>
In eclipse 3.6.1.
Rigth click on your compiled project -> Export
Next you should choose Java - JAR File from the tree
In new form appeared after you select options don't click finish but 'Next'.
Third form will be 'JAR Manifest Specification' and there you can choose your manifest file instead of eclipse generated one.