问题
I am attempting to make a cross platform .jar of a program that uses SWT for its GUI. I stumbled upon this and this, and have tried to use it in my own program. I am not very experienced with ant scripts, and this program has a lot of other .jars in its build path, so I used eclipse to generate an ant build script, which I modified to include the swtjar task. However, when the script runs and gets to the swtjar task, it fails and says that The archive swtjar.jar doesn't exist
. I also tried to make a legitimate build file earlier and also got this error. Is there something I'm missing? I've included swtjar.jar in the build path, and the taskdef at the top of the script.
Here's the script:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project kEllyIRClient">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required-->
<taskdef name="swtjar" classname="org.swtjar.ant.SWTJarTask"
classpath="./libs/swtjar.jar"/>
<target name="create_run_jar">
<!--make the release directory if it doesn't exist-->
<mkdir dir="./release/"/>
<!--Create a temporary jar file with all the dependencies (i.e. the libs folder)-->
<jar jarfile="./release/externalLibsTemp.jar">
<zipgroupfileset dir="./libs/">
<exclude name="swt/*swt*.jar"/>
<exclude name="swtjar.jar"/>
<include name="**/*.jar"/>
</zipgroupfileset>
</jar>
<!--package with swt-->
<swtjar jarfile="./release/KEllyIRC.jar" targetmainclass="shared.Initializer" swtversion="3.7.1">
<fileset dir="./bin"/>
<!--Add the dependencies jar to the jar, but exclude the meta-inf/manifest stuff
cause that screws stuff up.-->
<zipfileset excludes="META-INF/*.SF" src="./release/externalLibsTemp.jar" />
<fileset dir="./libs/swt/" includes="swt-win32-3.7.1.jar"/>
</swtjar>
<!--Delete temporary file-->
<delete file="./release/externalLibsTemp.jar"/>
</target>
And this is the error:
D:\My Dropbox\Java\kEllyIRClient\swtjar-buildV2.xml:24: The archive swtjar.jar doesn't exist
回答1:
I have left a comment asking for the output from running this ant target.
In the mean time, you are including your swt jars incorrectly and with the wrong names. You are using:
<zipfileset excludes="META-INF/*.SF" src="./libs/swtjar.jar"/>
<zipfileset excludes="META-INF/*.SF" src="./libs/org.eclipse.swt.win32.win32.x86_3.7.1.v3738a.jar"/>
- You don't need to include swtjar - the target will do that automatically for you. However, I suspect this is the step which isn't working for you.
- You also need to name your swt jars in the format "swt-<platform><bitness>-.jar". So in your case you need to rename "org.eclipse.swt.win32.win32.x86_3.7.1.v3738a.jar" to "swt-win32-3.7.1.jar".
- You shouldn't include the swt jars using zipfileset
Your renamed SWT jar should be included as follows.
<!-- SWT Jars -->
<fileset dir="./libs" includes="swt-win32-3.7.1.jar" />
Most of this is already covered on the swtjar site: http://mchr3k.github.com/swtjar/
回答2:
I know this is a really old question, but I found a solution that worked for me, but it probably won't help everyone. You see, SWTJar hates spaces.
What I mean, is, is that your directory path cannot have spaces in it. Otherwise SWTJar parses the path wrong, like shown below (my old jar script output):
[swtjar] /Users/generaluse/Documents/javagame/eclipse/FlippyChat 20MSG/swt/swtjar.jar
BUILD FAILED
/Users/generaluse/Documents/javagame/eclipse/FlippyChat MSG/build.xml:42: The archive swtjar.jar doesn't exist
Notice this part after [swtjar]
(which is generated by swtjar):
/FlippyChat 20MSG/
versus the BUILD FAILED
generated by ant:
/FlippyChat MSG/
Since SWTJar adds the 20, it looks in the wrong place, and cannot find its jar.
mchr, if you're reading this, can you fix it?
In the meantime I'd recommend using a hyphen (-) or underscore (_) instead of a space. It's programming standard anyway.
来源:https://stackoverflow.com/questions/9107509/unable-to-make-ant-script-with-swtjar