开发者

Error caused by executing an executable jar made by Apache Ant

开发者 https://www.devze.com 2023-04-11 11:19 出处:网络
I have created a Java application which has the following Apache Ant build file: <?xml version=\"1.0\" ?>

I have created a Java application which has the following Apache Ant build file:

<?xml version="1.0" ?>

<project name="GUI" basedir=".">

<property name="version" value="0.2"/>
<property name="bin.dir"                        value="${basedir}/bin"/>
<property name="gui_bin.dir"                    value="${basedir}/gui_bin"/>
<property name="src.dir"                        value="${basedir}/src"/>
<property name="jar.dir"                        value="${basedir}/jar"/>
<property name="images.dir"                     value="${basedir}/images"/>
<property name="user.properties"                value="${basedir}/user.properties"/>


<!-- ============ Clean target =================== -->
<!-- Delete output files and directories -->

<target name="clean" description="Clean the directory: build, ${gen-src.dir}*, ${test.report.dir}">
    <delete dir="${jar.dir}"/>
</target>


<!-- 
============ Compile target =================== 
-->
<target name="compile">
    <mkdir dir="${gui_bin.dir}"/>
    <javac srcdir="${src.dir}" destdir="${gui_bin.dir}" classpath="${basedir}/EFCore-1.0.0.jar" fork="true">
    </javac>
</target>


<!-- 
============ Create Executable Jar target =================== 
-->
<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
        <jar jarfile="jar/UPHECGui.jar" basedir="gui_bin" includes="**/*.class">
            <fileset dir="${basedir}">
                <include name="images/**/; EFCORE-1.0.0.jar" />
                </fileset>
                <manifest>
                    <attribute name="Main-Class" value="eu.keep.uphec.GUI"/>
                    <attribute name="Class-Path" value="EFCORE-1.0.0.jar"/>
                </manifest>
                <filelist dir="${basedir}" files="user.properties"/>
        </jar>
    </target>

<!-- 
    ============ Run target =================== 
    -->
<target name="run" depends="jar">
    <java classpath="jar/UPHECGui.jar;EFCORE-1.0.0.jar" classname="eu.keep.uphec.GUI" fork="true">      
    </java>
</target>

The tasks execute successfully: the jar task creates the jar and the run task launches successfully the application. When I go and try to execute the jar in a command line with the following code:

 C:\UPHECGUI\GUI-Project\ java -jar jar/UPHECGui.jar

the application throws the error:

Exception in thread "main" java.class.NoClassDefFoundError: eu/keep/kernel/CoreObserver
at.............
...............
...............
Could not find the main class: eu.keep.uphec.GUI. Program will exit.

Now, the GUI class with开发者_如何学编程 the main method is exactly in the specified folder (the run task executes successfully with this parameter). Here is a screenshot of the folder where the application is based:

Error caused by executing an executable jar made by Apache Ant

Can someone please tell me what's wrong with it? I spent hours trying to figure it out but nothing has come out yet :-( An help would be highly apreciated, thanks!!!!


The -jar option uses the manifest of the jar to set the classpath. Since your application depends on the jar EFCORE-1.0.0.jar, this jar should be in the classpath specified in the manifest of your UPHECGui.jar.

See http://download.oracle.com/javase/tutorial/deployment/jar/downman.html for explanations.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号