有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Jar文件找不到SWT库,但Eclipse可以

我有一个Ant构建(见下面的build.xml),它按照我在Eclipse中的预期编译和运行

然而,当我通过命令行(java -jar swtgui.jar)运行构建时,我收到以下错误:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout
        at java.lang.Class.getDeclaredMethods0(Native Method)
        ...
        etc

构建。xml

 <?xml version="1.0" encoding="UTF-8"?>

 <project default="run" name="My Project ">

 <target name="run" depends="createjar">
  <java classname="com.company.program.project.MyMainClass">
    <classpath path="staging">
      <fileset dir="C:\COMPANY\Eclipse\3.6-64\plugins">
        <include name="org.eclipse.swt.*.jar" />
      </fileset>
    </classpath>
   </java>
  </target>

 <target name="createjar" depends="compile">
  <jar destfile="./builds/jars/swtgui.jar" basedir="staging" filesetmanifest="mergewithoutmain">
      <manifest>
         <attribute name="Main-Class" value="com.company.program.project.MyMainClass" />
      </manifest>

    <fileset dir="C:\COMPANY\Eclipse\3.6-64\plugins\"     includes="org.eclipse.swt.win32.win32.x86_64_3.6.0.v3650b.jar" />
  </jar>
 </target>

<target name="compile">
    <javac includeantruntime="false" srcdir="./src" destdir="staging">
       <classpath>
            <fileset dir="C:\COMPANY\Eclipse\3.6-64\plugins">
              <include name="org.eclipse.swt.*.jar" />
            </fileset>
        </classpath>
    </javac>

</target>

<record name="./MyMainClass.log" loglevel="verbose" action="start"/>

这个错误对我来说没有意义,因为我为compile目标指定的SWT库路径与为createjar目标指定的路径相同

如果为compile目标找到了SWT库,为什么为createjar目标找不到它


共 (0) 个答案