1

嗨,我正在尝试创建一个可以从命令提示符运行的 ant 构建。当我运行包含主要方法的 jar 文件时,我得到了这个:

 Exception in thread "main" java.lang.NoClassDefFoundError: com/fmd/raptorurls/RaptorURLs
    Caused by: java.lang.ClassNotFoundException: com.fmd.raptorurls.RaptorURLs
            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)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: com.fmd.raptorurls.RaptorURLs. Program will exit.

这是我的蚂蚁构建:

<?xml version="1.0"?>
    <project name="RaptorURLCheck" basedir="." default="cleanDistFiles">
    <tstamp>
    <format property="currentYear" pattern="yyyy" />
    </tstamp>

    <!-- =================================================================== -->
    <!-- Global Properties - define in build.properties                      -->
    <!-- =================================================================== -->
    <property file="build.properties" />

    <!-- =================================================================== -->
    <!-- Paths                                                               -->
    <!-- =================================================================== -->
    <path id="runtime-libs">
    <fileset dir="${lib.dir}">
        <include name="**/*.jar" />
    </fileset>
    </path>

    <path id="manifest-classpath">
    <fileset dir="${lib.dir}">
        <include name="**/*.jar" />
    </fileset>
    </path>

    <manifestclasspath property="jar.classpath" jarfile="${lib.dir}/${project.name}.jar" >
    <classpath refid="manifest-classpath" />
    </manifestclasspath>

    <target name="clean" >
    <echo>***** Deleting files for ${project.name} *****</echo>
    <delete failonerror="false" dir="${bin.dir}" />
    <delete failonerror="false" dir="${dist.dir}" />
    <delete failonerror="false" dir="${log.dir}" />
    <delete failonerror="false" dir="${conf.dir}" />
    </target>

    <target name="init" depends="clean">
    <echo>***** Creating required directories for ${project.name} build *****</echo>
    <tstamp />
    <mkdir dir="${bin.dir}" />
    <mkdir dir="${dist.dir}" />
    <mkdir dir="${log.dir}" />
    <mkdir dir="${conf.dir}" />
    </target>

    <target name="compile" depends="init" >
    <echo>***** Compiling source files for ${project.name} *****</echo>
    <!--This javac compiles the java/src directory-->
    <javac srcdir="${src.dir}" includeantruntime="false" destdir="${bin.dir}" debug="on" debuglevel="lines,var,source">
        <include name="**/*.java" />
        <classpath refid="runtime-libs" />
    </javac>

    <copy todir="${bin.dir}">
        <fileset dir="${src.dir}">
        <include name="**/*.html" />
        <include name="**/*.css" />
        </fileset>
        <fileset dir="${config.dir}">
        <include name="*-.xml" />
        <include name="*.xsd" />
        <include name="*.properties" />
        </fileset>
    </copy>
    </target>

    <target name="jar" depends="compile" description="Packages app as jar" >
    <echo>***** Creating jar distribution for ${project.name} *****</echo>
    <jar destfile="${lib.dir}/${project.name}.jar">
        <manifest>
        <attribute name="Class-Path" value="${jar.classpath}" />
        <attribute name="Built-By" value="${user.name}" />
        <attribute name="Main-Class" value="${main.class}" />
        </manifest>
        <fileset dir="${bin.dir}">
        <include name="**/*.class*" />
        <include name="**/*.xml" />
        <include name="**/*.html" />
        <include name="**/*.css" />
        <include name="**/*.properties" />
        </fileset>
        <fileset dir="${config.dir}">
        <include name="**/*.xml" />
        <include name="**/*.xsd" />
        </fileset>
    </jar>
    </target>

    <target name="copyDistFiles" depends="jar">
    <echo>***** Copying distribution files for ${project.name} *****</echo>
    <mkdir dir="${dist.dir.lib}" />
    <mkdir dir="${dist.dir.conf}" />
    <mkdir dir="${dist.dir.log}" />
    <copy todir="${dist.dir.lib}">
        <fileset dir="${lib.dir}" excludes="*.db" />
    </copy>
    <copy todir="${dist.dir.conf}">
        <fileset dir="${conf.dir}" />
    </copy>
    </target>

    <target name="zip" depends="copyDistFiles">
    <echo>***** Zipping distribution files for ${project.name} *****</echo>
    <zip destfile="./Linux_5.5_${project.name}.zip" basedir="${dist.dir}" excludes="*.db" />
    </target>

    <target name="cleanDistFiles" depends="zip">
    <echo>***** Deleting distribution files for ${project.name} *****</echo>
    <delete dir="${dist.dir}/lib" />
    <delete dir="${dist.dir.conf}" />
    <delete dir="${dist.dir}/log" />
    </target>
</project>

这是我的构建属性:

  project.name=${ant.project.name}
    app.dir=${basedir}
    src.dir=${basedir}/src
    lib.dir=${basedir}/lib
    log.dir=${basedir}/logs
    conf.dir=${basedir}/config
    bin.dir=./bin
    bin.dir.lib=${bin.dir}/lib
    dist.dir=./dist
    dist.dir.conf=${dist.dir}/config
    dist.dir.lib=${dist.dir}/lib
    dist.dir.log=${dist.dir}/logs
    main.class=com.fmd.raptorurls.RaptorURLs
    spring.config.dir=./lib
    config.dir=./config/
    all.config.dir=./apps/fps/raptorurls/config
    build_env=all

不知道我做错了什么。我也在用弹簧

4

1 回答 1

0

A NoClassDefFoundError(与 a 不同ClassNotFoundException)可能表示许多事物。但首先,我猜想当你执行你的主类时,缺少一些依赖。检查您的运行时类路径。您需要的所有库都存在吗?

于 2012-06-06T13:42:50.303 回答