错误:无法找到或加载主类OCI_HelloWorld

时间:2016-05-05 10:30:58

标签: java ant jar

我是新的java,ant和stackoverflow。

我在Windows下的Project_Dir director下有一个build.xml文件并运行" ant run"命令运行OCI_HelloWorld.java文件,该文件位于" src"文件夹中。

运行" ant run"命令。

C:\Project_Dir>ant run
Buildfile: C:\Project_Dir\build.xml

run:
     [java] Error: Could not find or load main class OCI_HelloWorld
     [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 0 seconds

下面是我的build.xml文件

<!-- define the classpath for building the project -->
<path id="build.classpath">
    <!-- include jar files under lib directory -->
    <fileset dir="lib" includes="*.jar" />
</path>

<!-- define the classpath for running the project -->
<path id="run.classpath">
    <!-- include jar files under lib directory -->
    <fileset dir="lib" includes="*.jar" />

    <!-- include the jar file resulting from building the project -->
    <pathelement path="build/dist/OCI_HelloWorld.jar" />
</path>

<!-- build the jar file for the project -->
<target name="build" description="Build the HelloWorld program">

    <!-- first compile your java class code -->
    <mkdir dir="build/classes" />
    <javac includeantruntime="false" srcdir="src" destdir="build/classes" debug="true" includes="C:\Project_Dir\src\*.java" fork="yes" executable="C:\Program Files\Java\jdk1.7.0_79\bin\javac">
        <classpath refid="build.classpath" />
    </javac>

    <!-- now assemble a jar file from the compiled classes -->
    <mkdir dir="build/dist" />
    <jar jarfile="build/dist/OCI_HelloWorld.jar" fork="yes" basedir="build/classes">
        <fileset dir="build/classes" includes="**/*.*" />
    </jar>
</target>

<!-- run the project jar file -->
<target name="run" description="Run the HelloWorld program">
    <!-- run java on the resulting code -->
    <java classname="OCI_HelloWorld" fork="true" >
        <classpath refid="run.classpath" />
    </java>
</target>

<!-- reset build environment to starting point -->
<target name="clean" description="Cleans up your project build artifacts">
    <delete dir="build" />
</target>

请让我知道我需要做些什么才能摆脱这个错误。

0 个答案:

没有答案