问题描述
我正在尝试制作一个使用 SWT 作为其 GUI 的程序的跨平台 .jar.我偶然发现了 this 和 this,并尝试在我自己的程序中使用它.我对 ant 脚本不是很有经验,而且这个程序在它的构建路径中有很多其他 .jar,所以我使用 eclipse 生成了一个 ant 构建脚本,我修改了它以包含 swtjar 任务.但是,当脚本运行并到达 swtjar 任务时,它会失败并说 存档 swtjar.jar 不存在
.我之前也尝试制作一个合法的构建文件,但也遇到了这个错误.有什么我想念的吗?我在构建路径中包含了 swtjar.jar,在脚本顶部包含了 taskdef.
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.
脚本如下:
<?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>
这是错误:
D:\My Dropbox\Java\kEllyIRClient\swtjar-buildV2.xml:24: The archive swtjar.jar doesn't exist
推荐答案
我留下了一条评论,要求运行此 ant 目标的输出.
I have left a comment asking for the output from running this ant target.
与此同时,您错误地包含了 swt jar 并且名称错误.您正在使用:
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"/>
- 您不需要包含 swtjar - 目标会自动为您执行此操作.但是,我怀疑这是不适合您的步骤.
- 您还需要以swt-<platform><bitness>-.jar"格式命名您的 swt jar.因此,在您的情况下,您需要将org.eclipse.swt.win32.win32.x86_3.7.1.v3738a.jar"重命名为swt-win32-3.7.1.jar".
- 您不应该使用 zipfileset 包含 swt jar
您重命名的 SWT jar 应包含如下.
Your renamed SWT jar should be included as follows.
<!-- SWT Jars -->
<fileset dir="./libs" includes="swt-win32-3.7.1.jar" />
大部分内容已经在 swtjar 站点上进行了介绍:http://mchr3k.github.com/swtjar/
Most of this is already covered on the swtjar site: http://mchr3k.github.com/swtjar/
这篇关于无法使用 swtjar 制作 ant 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!