0

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
Community
  • 1
  • 1
Rahat Ahmed
  • 2,191
  • 2
  • 30
  • 40
  • Please paste the code of how you modified build script to include swtjar – Ved Feb 02 '12 at 05:31
  • Please paste the output which you get when you try to run this target – mchr Feb 03 '12 at 15:14
  • Please post the lines of output preceding this error. For example one of my own projects produces the following lines of output: [swtjar] \Users\username\Documents\Workspaces\Github\InTrace\org.intrace\lib\swtjar.jar [swtjar] Building jar: C:\Users\username\Documents\Workspaces\Github\InTrace\org.intrace\build\jars\i ntrace-ui.jar. – mchr Feb 05 '12 at 22:21
  • Can you also please retry with your project on your C drive? It is possible that the current swtjar task is bugged and doesn't work from the D drive. – mchr Feb 05 '12 at 22:22

2 Answers2

2

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/

mchr
  • 6,161
  • 6
  • 52
  • 74
  • Ah, sorry for the second point, that was a mistake on my part(it was originally named correctly). I tried excluding swtjar.jar and using fileset for the swt-win32 jar instead, but unfortunately I still get the same error. Strangely enough, while working, I had an accidental typo on the last line before , and the script ran up to that. I've updated the script in the question with the code that I have now., along with the error message. – Rahat Ahmed Feb 04 '12 at 03:18
  • I have the same error: The archive swtjar.jar doesn't exist. I've followed your guide but I always end with the same error. – Gabriel Llamas Aug 07 '12 at 16:25
  • Can you post your full build.xml file? What directory are you running ant from? What OS are you using? – mchr Aug 07 '12 at 22:50
0

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.

Dynomyte
  • 181
  • 4