我已经构建了一个相当大的 java 应用程序,我想将它作为桌面应用程序运行。它还有其他几个需要工作的目录,以及包含类的 bin 文件夹,如图像文件夹、第 3 方 api、如数据库 jar 等。我有一个 build.xml 来创建 jar,但是jar 不运行。找不到其中一个 api 似乎是一个错误。
这是错误:
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 创建桌面应用程序的教程,但似乎无法做到这一点。
更新/编辑通过 Jayan 下面的评论,我认为我的问题确实不包括正确的类路径。所以我更新了我的 build.xml 文件以包含一个路径转换属性并将属性类路径添加到 jar 目标。但是,我仍然得到与上面发布的完全相同的错误。