我已经构建了一个相当大的java应用程序,我希望将其作为桌面应用程序运行。它有几个需要工作的其他目录,以及包含类的bin文件夹,如images文件夹,第三方api,如数据库jar等。我有一个build.xml创建jar,但是jar不运行。似乎是一个错误,其中一个apis没有找到。
这是错误:
Exception in thread "main" java.lang.NoClassDefFoundError: bibliothek/gui/dock/c
ommon/CContentArea
at pos.main.POSsystem.<init>(Unknown Source)
at pos.main.POSsystem.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: bibliothek.gui.dock.common.CContent
Area
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Exception in thread "main" java.lang.NoClassDefFoundError: bibliothek/gui/dock/c
ommon/CContentArea
at pos.main.POSsystem.<init>(Unknown Source)
at pos.main.POSsystem.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: bibliothek.gui.dock.common.CContent
Area
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
如果您对build.xml文件感到好奇,那么它是:
<?xml version="1.0"?>
<project name="POSsystem" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" /> <!--the default bin eclipse folder-->
<property name="shipping.dir" location="shipping" />
<property name="doc.dir" location="doc" />
<property name="main-class" value="pos.main.POSsystem" />
<property name="splash-screen" value="images/splash.png" />
<property name = "jars.dir" value="libs" />
<property environment="env"/>
<property name="ECLIPSE_HOME" value="C:\eclipse"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id= "jars.path">
<fileset dir="${jars.dir}" includes="**/*.jar" />
</path>
<path id="pos.classpath">
<pathelement location="bin"/>
<pathelement location="${jars.dir}/docking-frames-common.jar"/>
<pathelement location="${jars.dir}/docking-frames-core.jar"/>
<pathelement location="${jars.dir}/hsqldb.jar"/>
</path>
<!--THIS IS THE ADDED CODE FOR THE CLASSPATH-->
<pathconvert property="manifest.classpath" pathsep=" ">
<path refid="pos.classpath"/>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from="*.jar" to="libs/*.jar"/>
</chainedmapper>
</mapper>
</pathconvert>
<!-- Deletes the existing build, doc and shipping directory-->
<target name="clean">
<echo>"Cleaning..."</echo>
<delete dir="${build.dir}" />
<delete dir="${shipping.dir}" />
<delete dir="${doc.dir}" />
<echo>"Done Cleaning..."</echo>
</target>
<!-- Creates the build, doc and shipping directory-->
<target name="makedir" depends="clean">
<echo>"Making Directories..."</echo>
<mkdir dir="${build.dir}" />
<mkdir dir="${doc.dir}" />
<mkdir dir="${shipping.dir}" />
</target>
<!-- Compiles the java code -->
<target name="compile" depends="makedir"> <!--depends="doc"> CHANGE BACK WHEN YOU RE-IMPLEMENT DOC-->
<echo>"Compiling..."</echo>
<javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime = "false" classpathref="jars.path" />
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<echo>"Making Jar..."</echo>
<jar destfile="${shipping.dir}\POSsystem.jar" basedir="${build.dir}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="${manifest.classpath}" />
<attribute name = "SplashScreen-Image" value="${splash-screen}" />
</manifest>
</jar>
</target>
<target name="main" depends="jar"><!--depends="run"> CHANGE BACK WHEN YOU RE-IMPLEMENT RUN-->
<description>Main target</description>
<echo>Main...</echo>
<!--run it here for now instead of from the jar-->
<java classname="pos.main.POSsystem" failonerror="true" fork="yes">
<jvmarg line="-splash:images/splash.png"/>
<classpath refid="pos.classpath"/>
</java>
</target>
</project>
如果我将build.xml作为ant构建运行,那么它将全部编译,并且通过构建也将运行应用程序,但jar不会。
如果我遗漏了任何有用的信息,请告诉我。我已经阅读了很多关于使用java创建桌面应用程序的教程,但似乎无法做到这一点。
UPDATE /编辑 通过Jayan下面的评论,我认为我的问题确实不包括正确的类路径。所以我更新了我的build.xml文件以包含路径转换属性,并将属性class-path添加到jar目标。但是,我仍然得到与上面发布的完全相同的错误。