简体   繁体   English

Apache Ant java.lang.NoClassDefFoundError

[英]Apache Ant java.lang.NoClassDefFoundError

Possible Answer Stack Over flow question可能的答案堆栈溢出问题

My problem is same as described in the above thread.I went throught the solution and its not working.我的问题与上述线程中描述的相同。我经历了解决方案但它不起作用。 ant compile working perfectly.蚂蚁编译工作完美。 ant jar saying cant load the main class ant jar说不能加载主类

Exception in thread "main" java.lang.NoClassDefFoundError: LoadServer (wrong name: org/module/loader/LoadServer)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

I did the following in commnad line我在命令行中执行了以下操作

JAVA_HOME="/usr/local/java/jdk1.7.0_21"
ANT_HOME="/usr/share/ant/"
PATH="$ANT_HOME/bin:$PATH"

Morever if I start a new terminal and type echo$JAVA_HOME its showing the above result but echo$ANT_HOME is giving null.此外,如果我启动一个新终端并输入echo$JAVA_HOME ,它会显示上述结果,但echo$ANT_HOME给出的是空值。

here is a screen shot 这是一个屏幕截图

Initial Error初始错误

     <project name="Raxa-4" basedir="." default="main">

    <property name="src.dir"      value="src"/>
    <property name="prop.dir"     value="properties"/>
    <property name="resource.dir" value="resource"/>
    <property name="lib.dir"      value="lib"/>
    <property name="build.dir"    value="build"/>
    <property name="classes.dir"  value="${build.dir}/classes"/>
    <property name="jar.dir"      value="${build.dir}/jar"/>
    <property name="main-class"   value="org.raxa.module.loader.LoadServer"/>

    <path id="classpath">
            <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false" />
        <copy todir="${classes.dir}">
            <fileset dir="${resource.dir}" excludes="**/*.java"/>
            <fileset dir="${prop.dir}" excludes="**/*.java"/>
        </copy>
    </target>

   <target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
         <classpath>
            <path refid="classpath"/>
            <path location="${jar.dir}/${ant.project.name}.jar"/>
        </classpath>
        </jar>
    </target>


    <target name="run" depends="jar">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>

    </target>

    <target name="clean-build" depends="clean,jar"/>

    <target name="main" depends="clean,run"/>

</project>

Edited:编辑:

    <property name="src.dir"      value="src"/>
    <property name="prop.dir"     value="properties"/>
    <property name="resource.dir" value="resource"/>
    <property name="lib.dir"      value="lib"/>
    <property name="build.dir"    value="build"/>
    <property name="classes.dir"  value="${build.dir}/classes"/>
    <property name="jar.dir"      value="${build.dir}/jar"/>
    <property name="main-class"   value="org.raxa.module.loader.LoadServer"/>

    <path id="classpath">
            <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false" />
        <copy todir="${classes.dir}">
            <fileset dir="${resource.dir}" excludes="**/*.java"/>
            <fileset dir="${prop.dir}" excludes="**/*.java"/>
        </copy>
    </target>

   <target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>


    <target name="run" depends="jar">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
        <classpath>
            <path refid="classpath"/>
            <path location="${jar.dir}/${ant.project.name}.jar"/>
        </classpath>
    </target>

    <target name="clean-build" depends="clean,jar"/>

    <target name="main" depends="clean,run"/>

</project>

NEW ERROR on ant run蚂蚁运行的新错误

run:跑:

[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
 [java]     at org.raxa.module.scheduler.TimeSetter.<clinit>(Unknown Source)
 [java]     at org.raxa.module.loader.LoadServer.main(Unknown Source)
 [java] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
 [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
 [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
 [java]     at java.security.AccessController.doPrivileged(Native Method)
 [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
 [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
 [java]     ... 2 more
 [java] Java Result: 1

BUILD FAILED
/home/atul/Documents/workspace2/Raxa-4/build.xml:41: Problem: failed to create task or type classpath
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken pla

Maybe the problem is that your classpath gets overriden.也许问题是你的类路径被覆盖了。 Try this one:试试这个:

<java classname="${main-class}" fork="true" >
  <classpath>
    <path refid="classpath"/>
    <pathelement location="${jar.dir}/${ant.project.name}.jar"/>
  </classpath>
</classpath> </java>

You don't need ANT_HOME defined because the shell script ant will set that for you.您不需要定义ANT_HOME ,因为 shell 脚本ant会为您设置它。 However, if you did EXPORT ANT_HOME , you'll see it when you start a new terminal.但是,如果您执行了EXPORT ANT_HOME ,您将在启动新终端时看到它。 Until you export an environment variable, it won't show up in child processes.在您导出环境变量之前,它不会出现在子进程中。

I noticed that the Ant class isn't showing up in the call.我注意到 Ant 类没有出现在通话中。 You should have seen some call to org.apache.tools.ant somewhere in the stack trace if this was an Ant issue.如果这是 Ant 问题,您应该已经在堆栈跟踪中的某处看到了对org.apache.tools.ant的调用。 Can you run any other build task?您可以运行任何其他构建任务吗? Try:尝试:

$ ant clean

Does that work?那样有用吗?

Ant has extensive debugging trace which shows you way more information than you want to know. Ant 具有广泛的调试跟踪,它向您显示比您想知道的更多的信息。 Try running ant with the -d parameter:尝试使用-d参数运行ant

$ ant -d compile | tee ant.out

This will produce a lot of output which is why you need to pipe this into a file.这将产生大量输出,这就是为什么您需要将其通过管道传输到文件中的原因。 Look at ant.out and see where it's failing.查看ant.out并查看它失败的地方。 Did it call the compile task?它调用了compile任务吗?

The ant-launcher calls ant.jar which then calls org.ant.tools.taskdefs.javac (If I remember the path) which then does a system command to call the javac executable directly. ant-launcher 调用ant.jar ,然后调用org.ant.tools.taskdefs.javac (如果我记得路径),然后执行系统命令直接调用javac可执行文件。 One of the things the dump will show is the exact command being executed when the compilation is done.转储将显示的一件事是编译完成时正在执行的确切命令。

This will probably help you find where the error is happening.这可能会帮助您找到错误发生的位置。 It could be that javac itself isn't executing, or that it is missing.可能是javac本身没有执行,或者它丢失了。 I've seen this before where someone accidentally pointed JAVA_HOME to a JRE and not a JDK.我以前见过有人不小心将JAVA_HOME指向 JRE 而不是 JDK。 I've also seen this where the executable was 64bits, but the OS was 32bits.我也见过可执行文件是 64 位的,但操作系统是 32 位的。

If the dump shows you the actual Java command being executed, see if you can copy it, and paste it into a shell script and execute the javac command directly.如果转储显示正在执行的实际 Java 命令,请查看是否可以复制它,并将其粘贴到 shell 脚本中并直接执行javac命令。 This way, we can see if the issue is with javac or with Ant.这样,我们可以查看问题出在javac还是 Ant 上。 If you can execute javac without Ant, it's an Ant issue.如果你可以在没有 Ant 的情况下执行javac ,那是 Ant 的问题。 Otherwise, it's an issue with your Java installation.否则,这是您的 Java 安装的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 apache java.lang.NoClassDefFoundError - apache java.lang.NoClassDefFoundError 运行ant时java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError when running ant java.lang.NoClassDefFoundError ANT build - java.lang.NoClassDefFoundError ANT build Eclipse中的java.lang.NoClassDefFoundError,但不包含Ant - java.lang.NoClassDefFoundError in Eclipse, but not with Ant java.lang.NoClassDefFoundError + ant-运行一个jar - java.lang.NoClassDefFoundError + ant - running a jar Ant失败:线程“main”中的异常java.lang.NoClassDefFoundError org / apache / tools / ant / launch / Launcher - Ant failure: Exception in thread “main” java.lang.NoClassDefFoundError org/apache/tools/ant/launch/Launcher Apache Spark-java.lang.NoClassDefFoundError - Apache spark - java.lang.NoClassDefFoundError Ant,Tomcat构建错误:java.lang.NoClassDefFoundError:org / apache / tomcat / util / buf / B2CConverter - Ant, Tomcat Build Error: java.lang.NoClassDefFoundError: org/apache/tomcat/util/buf/B2CConverter java.lang.NoClassDefFoundError:org / apache / tools / ant / util / ReaderInputStream javaFx + intelliJ - java.lang.NoClassDefFoundError: org/apache/tools/ant/util/ReaderInputStream javaFx+intelliJ Ant构建问题:嵌套异常是java.lang.NoClassDefFoundError:org / apache / tiles / request / servlet / ServletApplicationContext - Ant Build Issue: nested exception is java.lang.NoClassDefFoundError: org/apache/tiles/request/servlet/ServletApplicationContext
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM