У меня есть программа на Java, использующая количество внешних библиотек. Программа компилируется и запускается в Eclipse IDE без каких-либо проблем. Однако при использовании ant build.xml компиляция работает нормально, но выдает следующее исключение во время выполнения.
run:
[java] Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/jna/Library
[java] at java.lang.ClassLoader.defineClass1(Native Method)
[java] at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
[java] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[java] at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
[java] at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] at org.freedesktop.gstreamer.Gst.getVersion(Unknown Source)
[java] at org.freedesktop.gstreamer.Gst.init(Unknown Source)
[java] at org.freedesktop.gstreamer.Gst.init(Unknown Source)
[java] at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
[java] at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
[java] at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
[java] at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
[java] at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
[java] at java.awt.Component.processMouseEvent(Component.java:6539)
[java] at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
[java] at java.awt.Component.processEvent(Component.java:6304)
[java] at java.awt.Container.processEvent(Container.java:2239)
[java] at java.awt.Component.dispatchEventImpl(Component.java:4889)
[java] at java.awt.Container.dispatchEventImpl(Container.java:2297)
[java] at java.awt.Component.dispatchEvent(Component.java:4711)
[java] at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
[java] at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
[java] at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
[java] at java.awt.Container.dispatchEventImpl(Container.java:2283)
[java] at java.awt.Window.dispatchEventImpl(Window.java:2746)
[java] at java.awt.Component.dispatchEvent(Component.java:4711)
[java] at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
[java] at java.awt.EventQueue.access$500(EventQueue.java:97)
[java] at java.awt.EventQueue$3.run(EventQueue.java:709)
[java] at java.awt.EventQueue$3.run(EventQueue.java:703)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
[java] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
[java] at java.awt.EventQueue$4.run(EventQueue.java:733)
[java] at java.awt.EventQueue$4.run(EventQueue.java:731)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
[java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
[java] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
[java] at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
[java] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
[java] at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
[java] Caused by: java.lang.ClassNotFoundException: com.sun.jna.Library
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 52 more
Используемый мной скрипт сборки приведен ниже.
<property name="src.dir" value="src/org"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="lib.dir" value="Libs" />
<property name="main-class" value="org.ai.receiver.DashboardLauncher"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}/ai/receiver:${src.dir}/freedesktop/gstreamer" destdir="${classes.dir}" includeantruntime="false">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true">
<classpath>
<pathelement location="Libs/jna.jar:Libs/jna-platform.jar:Libs/swt.jar"/>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</java>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
Необходимые файлы внешних библиотек "jna.jar", "jna-platform.jar" и "swt.jar" находятся в "Каталог "Lib".
Мне кажется, что эти внешние библиотеки не загружаются должным образом во время выполнения, но они должным образом связаны во время компиляции. Подобная проблема обсуждается в этом github security tracker , но обсуждение не обеспечивает правильного решения.
Не могли бы вы помочь мне решить эту проблему?
Спасибо.