可能的答案堆栈溢出问题
我的问题与上述线程中描述的相同。我经历了解决方案但它不起作用。 蚂蚁编译工作完美。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)
我在命令行中执行了以下操作
JAVA_HOME="/usr/local/java/jdk1.7.0_21"
ANT_HOME="/usr/share/ant/"
PATH="$ANT_HOME/bin:$PATH"
此外,如果我启动一个新终端并输入echo$JAVA_HOME,它会显示上述结果,但echo$ANT_HOME给出的是空值。
初始错误
<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>
编辑:
<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>
蚂蚁运行的新错误
跑:
[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
行政长官