简体   繁体   English

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

I'm on Fedora 17. I am trying to compile a project with an ant build file which is not compatible with Java 7. So I decided to install OpenJDK 6. JDK 6 is unfortunately removed from yum repositories, and I figured it would be easy to install it manually. 我正在使用Fedora 17.我正在尝试使用与Java 7不兼容的ant构建文件编译项目。所以我决定安装OpenJDK 6.不幸的是,JDK 6从yum存储库中删除了,我认为它将是易于手动安装。 I learned that there is no JAVA_HOME variable and alternatives system is used instead. 我了解到没有JAVA_HOME变量,而是使用替代系统。 So I downloaded OpenJDK binaries (from OSG if it matters) and installed java & javac & javaws using alternatives --install command. 所以我下载了OpenJDK二进制文件(如果重要的话,从OSG下载)并使用alternatives --install命令安装了java&javac和javaws。 Checking java --version and javac --version proved it to be successful. 检查java --versionjavac --version证明它是成功的。 But the strange thing happened is that ant is not working any more! 但奇怪的是,蚂蚁不再工作了! When I type ant --execdebug I receive this message: 当我输入ant --execdebug我收到以下消息:

exec "/usr/lib/jvm/openjdk-6.0.24/bin/java" -classpath "/usr/bin/build-classpath: 
error: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24 does not exist or is not a 
directory:/usr/bin/build-classpath: error: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24 
does not exist or is not a directory:/usr/lib/jvm/openjdk-6.0.24/lib/tools.jar"
-Dant.home="/usr/share/ant" -Dant.library.dir="/usr/share/ant/lib" 
org.apache.tools.ant.launch.Launcher -cp ""
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.

As the case with java, there is no ANT_HOME variable too. 与java一样,也没有ANT_HOME变量。 But there wasn't an ANT_HOME even before installing java 6 while it was working fine. 但是在安装java 6之前没有ANT_HOME,而它工作正常。 Ant is installed under /usr/bin/ant that's already in PATH. Ant安装在已经在PATH中的/ usr / bin / ant下。

UPDATE: I know there are similar questions qustion 1 , question 2 . 更新:我知道有类似问题qustion 1问题2 But neither resolved my problem. 但都没有解决我的问题。 For example adding ANT_HOME=/usr/bin deteriorates the situation, in that ant is not working even with JDK 7! 例如,添加ANT_HOME = / usr / bin会使情况恶化,因为即使使用JDK 7,ant也无法正常工作! Due to my unfamiliarity with alternatives system, I totally removed java related alternatives, added JAVA_HOME, and modified PATH instead. 由于我不熟悉替代系统,我完全删除了Java相关的替代方案,添加了JAVA_HOME,并修改了PATH。 Again, java & javac are working fine, with java --version returning the right version, but ant is returning the same error. 同样,java和javac工作正常,java --version返回正确的版本,但ant返回相同的错误。 As the --execdebug tells us, JVM_LIBDIR is not pointing to the right location. 正如--execdebug告诉我们的那样,JVM_LIBDIR没有指向正确的位置。 I suppose that the value is set in java.conf file, so I'm pasting it here (I've installed JDK 6 & 7 on /usr/lib/jvm): 我想这个值是在java.conf文件中设置的,所以我在这里粘贴它(我在/ usr / lib / jvm上安装了JDK 6&7):

# System-wide Java configuration file                                -*- sh -*-
#
# JPackage Project <http://www.jpackage.org/>

# Location of jar files on the system
JAVA_LIBDIR=/usr/share/java

# Location of arch-specific jar files on the system
JNI_LIBDIR=/usr/lib64/java

# Location for noarch jar files using arch-specifics jar files
JAVAJNI_LIBDIR=/usr/share/java-jni

# Root of all JVM installations
JVM_ROOT=/usr/lib/jvm

# You can define a system-wide JVM root here if you're not using the
# default one.
#
# If you have the a base JRE package installed
# (e.g. java-1.6.0-openjdk):
#JAVA_HOME=$JVM_ROOT/jre
#
# If you have the a devel JDK package installed
# (e.g. java-1.6.0-openjdk-devel):
#JAVA_HOME=$JVM_ROOT/java-1.7.0-openjdk-1.7.0.9.x86_64
JAVA_HOME=$JVM_ROOT/openjdk-6.0.24

# Options to pass to the java interpreter
JAVACMD_OPTS=

By just commenting and uncommenting the corresponding lines in java.conf, it turns that ant is working fine with 7 and fails with 6. when I echo JVM_LIBDIR just before java command in the ant shell, I receive user/share/java as stated in java.conf. 通过只注释和取消注释java.conf中的相应行,它转为ant使用7工作正常并且失败为6.当我在ant shell中的java命令之前回显JVM_LIBDIR时,我接收到user/share/java java.conf。 But ant --execdebug has returned something strange: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24 . 但是ant --execdebug已经返回了一些奇怪的内容: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24 What is that and how can I fix it? 那是什么,我该如何解决?

If you could not tell the problem here, what is the neatest and safest way to install multiple versions of JDK, that can be switched easily? 如果你不能在这里说出问题,安装多个版本的JDK最简单,最安全的方法是什么,可以轻松切换?

Any help is well appreciated. 任何帮助都非常感谢。

You are missing a jar on the classpath. 你在类路径上缺少一个jar。 Make sure you have all the required libraries in the lib folder from which ant is picking up the dependencies. 确保lib文件夹中包含所有必需的库,其中ant正在从中获取依赖项。

Check this similar question. 检查这个类似的问题。

I can only answer the last question. 我只能回答最后一个问题。

WE DO NOT USE THE ALTERNATIVE SYSTEM, instead, we manage it manually. 我们不使用替代系统,而是手动管理它。

What we do in both Ubuntu and CentOS is that we always use the tar.gz from Oracle JDK website, extract it to a subfolder in /opt (like /opt/jdk_1.7.0_09 ), make a symbol link to the folder (like /opt/default_jdk -> /opt/jdk_1.7.0_09 ), and set the environment varibles where we point JAVA_HOME to the symbol link rather than the actual folder ( JAVA_HOME=/opt/default_jdk ). 我们在Ubuntu和CentOS中所做的是我们总是使用来自Oracle JDK网站的tar.gz,将其解压缩到/ opt中的子文件夹(如/opt/jdk_1.7.0_09 ),创建一个指向该文件夹的符号链接(如/opt/default_jdk -> /opt/jdk_1.7.0_09 ),并设置环境变量,我们将JAVA_HOME指向符号链接而不是实际文件夹( JAVA_HOME=/opt/default_jdk )。

In this way, if we want to change or update the jdk (eg from JDK 7 upadte 9 to JDK 7 upadte 15), we just download the tar.gz package, extract it to another folder (eg /opt/jdk_1.7.0_15 ), delete the old symbol link (which points to /opt/jdk_1.7.0_09 ) and create a new one pointing to the new folder (eg /opt/default_jdk -> /opt/jdk_1.7.0_15 ). 这样,如果我们想要更改或更新jdk(例如从JDK 7 upadte 9到JDK 7 upadte 15),我们只需下载tar.gz包,将其解压缩到另一个文件夹(例如/opt/jdk_1.7.0_15 ),删除旧符号链接(指向/opt/jdk_1.7.0_09 )并创建一个指向新文件夹的新符号链接(例如/opt/default_jdk -> /opt/jdk_1.7.0_15 )。

Same way works with 32 and 64 bit jdks, different versions of Ant, Maven, Gradle, etc. 相同的方式适用于32和64位jdks,不同版本的Ant,Maven,Gradle等。

Looks like something is wrong with your Java installation. 看起来你的Java安装有问题。 Refer this http://www.linuxforums.org/forum/red-hat-fedora-linux/151698-problems-tomcat.html with a similar issue which got resolved later. 请参阅此http://www.linuxforums.org/forum/red-hat-fedora-linux/151698-problems-tomcat.html以及稍后解决的类似问题。

暂无
暂无

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

相关问题 使用ant构建之后线程主java.lang.noclassdeffounderror中的异常 - exception in thread main java.lang.noclassdeffounderror after build with ant 用ant构建jar:线程“ main”中的异常java.lang.NoClassDefFoundError - Built jar with ant: Exception in thread “main” java.lang.NoClassDefFoundError 线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / commons / discovery / tools / DiscoverSingleton - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/discovery/tools/DiscoverSingleton 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 脚本错误:线程“ main”中的异常java.lang.NoClassDefFoundError:org / codehaus / classwor lds / Launcher - Script Error: Exception in thread “main” java.lang.NoClassDefFoundError: org/codehaus/classwor lds/Launcher apache ant 无法找到或加载主类 org.apache.tools.ant.launch.Launcher - apache ant Could not find or load main class org.apache.tools.ant.launch.Launcher Apache Ant java.lang.NoClassDefFoundError - Apache Ant java.lang.NoClassDefFoundError Java Apache Spark Maven Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/SparkConf - Java Apache Spark Maven Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/SparkConf 线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / commons / lang / builder / CompareToBuilder - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM