我的ant配置有什么问题?
我使用 yum 在 Fedora 5 机器上安装了 Ant,但 Ant 没有启动。我收到此错误消息:
[bash]# ant
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:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
我已设置以下环境变量:
JAVA_HOME = /usr/java/latest
ANT_HOME = /usr/bin
Ant 安装在 /usr/bin/ant
。
我也遇到过这篇文章,似乎JAVAVER_LIBDIR
变量不指向存在的东西。我设置了一个符号链接,就像帖子建议的那样,为作者解决了问题,但它并没有为我解决问题。
[bash]# sudo ln -s /usr/share/java /usr/share/java-1.6.0
编辑:我还设置了一个符号链接来解决与 JAVAVER_JNIDIR
变量类似的问题:
[bash]# sudo ln -s /usr/lib/java /usr/lib/java-1.6.0
我现在收到不同的错误消息:
[bash]# ant --execdebug
/usr/bin/build-classpath: error: Could not find jaxp_parser_impl Java extension for this JVM
/usr/bin/build-classpath: error: Could not find xml-commons-apis Java extension for this JVM
/usr/bin/build-classpath: error: Some specified jars were not found
exec "/usr/java/latest/bin/java" -classpath "/usr/share/java-1.6.0/ant.jar:/usr/share/java-1.6.0/ant-launcher.jar:/usr/java/latest/lib/tools.jar" -Dant.home="/usr" -Dant.library.dir="/usr/lib" org.apache.tools.ant.launch.Launcher -cp ""
Buildfile: build.xml does not exist!
Build failed
关闭 Google 这些错误消息...
I installed Ant on a Fedora 5 machine using yum, but Ant does not launch. I get this error message:
[bash]# ant
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:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
I have set the following environment variables:
JAVA_HOME = /usr/java/latest
ANT_HOME = /usr/bin
Ant is installed at /usr/bin/ant
.
I have also come across this post, and it seems that the JAVAVER_LIBDIR
variable does not point to something that exists. I set a symbolic link, like the post suggests cleared the issue up for the author, but it did not fix things for me.
[bash]# sudo ln -s /usr/share/java /usr/share/java-1.6.0
Edit: I have also set a symbolic link that addressed a similar problem with the JAVAVER_JNIDIR
variable:
[bash]# sudo ln -s /usr/lib/java /usr/lib/java-1.6.0
I now get a different error message:
[bash]# ant --execdebug
/usr/bin/build-classpath: error: Could not find jaxp_parser_impl Java extension for this JVM
/usr/bin/build-classpath: error: Could not find xml-commons-apis Java extension for this JVM
/usr/bin/build-classpath: error: Some specified jars were not found
exec "/usr/java/latest/bin/java" -classpath "/usr/share/java-1.6.0/ant.jar:/usr/share/java-1.6.0/ant-launcher.jar:/usr/java/latest/lib/tools.jar" -Dant.home="/usr" -Dant.library.dir="/usr/lib" org.apache.tools.ant.launch.Launcher -cp ""
Buildfile: build.xml does not exist!
Build failed
Off to Google these error messages...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
我刚刚在 Fedora 18 上遇到了类似的问题。
长话短说,运行:
显然,这个问题特定于
java-1.7.0-openjdk
因为类似 empty所有其他 JDK 版本的目录均已存在。详情
运行
ant
后出现单行错误:问题出在
/usr/share/java-utils/java-functions
脚本中它尝试设置JAVAVER_JNIDIR
/JAVAVER_LIBDIR
变量来引用上面的目录。由于错误消息重定向到 stdout 不适当,某些变量得到了如下分配:根据所有其他 java 版本设置的约定创建目录是最干净的解决方案。
I've just met similar issue on Fedora 18.
To make long story short, run:
Apparently, this problem is specific to
java-1.7.0-openjdk
because similar empty directories for all other JDK versions existed.DETAILS
There was single-line error after running
ant
:The problem was somewhere in
/usr/share/java-utils/java-functions
script which tried to setJAVAVER_JNIDIR
/JAVAVER_LIBDIR
variables to refer to the directories above. Due to inappropriate error message redirection to stdout, some variables got assignments like:Creating the directories according to the convention set by all other java versions is the cleanest solution.
我通过下载 tar 文件并将其放在 /opt 中来安装 sun java 1.7.x。因为我没有执行 yum install,所以没有创建这些目录。我的 JAVA_HOME 设置为:
正如其他人所说,运行以下命令提供了非常有用的调试:
I installed sun java 1.7.x by downloading the tar file and placing it in /opt. Because I didn't do a yum install these directories were not created. My JAVA_HOME is set to:
As someone else said, running the following provided very useful debug:
我认为 ANT_HOME 应该设置为“/usr/bin/ant”。我有这样的配置(CENTOS 5)。
我在“/etc/profile.d”下的 sh 脚本有这样的配置:
我希望它对你有帮助。
I think that the ANT_HOME should be set with '/usr/bin/ant'. I have that configuration (CENTOS 5).
My sh script under '/etc/profile.d' has this conf.:
I hope it helps you.
我遇到了类似的问题,但以下内容为我解决了:
I had a similar problem but the following fixed it for me:
我今天有同样的错误消息,但由不同的原因触发。
就我而言,更新到 OpenJDK 1.8.0 后,我无法再运行 ant。
问题在于 java -fullversion 命令的输出略有变化,并且 /usr/share/java-utils/java-functions 不再正确明白了。
升级到最新版本的
jpackage-utils
RPM 为我解决了这个问题。I had the same error message today, but triggered by a different cause.
In my case, after I updated to OpenJDK 1.8.0, I could no longer run ant.
The problem lied with the fact that the output of the
java -fullversion
command had changed slightly, and the/usr/share/java-utils/java-functions
no longer correctly understood it.Upgrading to the latest version of the
jpackage-utils
RPM solved it for me.我在 Fedora 16 上遇到了这样的问题,但就我而言,
xerces
包和xml-commons-apis
没问题。实际上,--execdebug
非常有帮助,它打印出ant无法在/usr/lib/jvm-exports/YOUR_JDK
找到目录。这是因为我从openjdk切换到oracle的jdk,并且以前版本的jdk的目录(/usr/lib/jvm-exports/java-1.6.0-openjdk-1.6.0.0
)留在那里,但是没有我当前的版本(/usr/lib/jvm-exports/jdk1.6.0_32
)。这些目录只包含一堆指向特定 jre 的 jar 的软链接,因此我采取了以下步骤:jdk1.6.0_32
) 创建一个新目录,# cp -av java-1.6.0-openjdk-1.6.0.0.x86_64/* jdk1.6.0_32/
# cd /usr/lib/jvm-exports/jdk1.6.0_32
# ln -s -f $JAVA_HOME/jre/lib/rt.jar jaas-1.6.0.0 .jar
显然,
$JAVA_HOME
设置正确(在新的 jdk 版本上)。它解决了我的问题,并且可能是除上述原因之外的另一个原因。
I had such problem on Fedora 16 but in my case
xerces
packages andxml-commons-apis
was ok. Actually,--execdebug
is very helpful and it printed that ant cannot find a directory at/usr/lib/jvm-exports/YOUR_JDK
. This was because I switched from openjdk to oracle's jdk and the directory of former version of jdk (/usr/lib/jvm-exports/java-1.6.0-openjdk-1.6.0.0
) left there but there was not the one of my current version (/usr/lib/jvm-exports/jdk1.6.0_32
). These directories includes only a bunch of soft links that point to particular jre's jars so I've taken following steps:jdk1.6.0_32
)# cp -av java-1.6.0-openjdk-1.6.0.0.x86_64/* jdk1.6.0_32/
# cd /usr/lib/jvm-exports/jdk1.6.0_32
# ln -s -f $JAVA_HOME/jre/lib/rt.jar jaas-1.6.0.0.jar
Obviously,
$JAVA_HOME
is set correctly (on the new jdk version).It solved my problem and can be another cause excepting the causes mentioned above.
尝试安装
xerces-j2-xml-apis
Try installing
xerces-j2-xml-apis
就我而言,我设置了
ANT_HOME
变量,但附加了/bin/
以便在系统路径中使用 - 此主变量不应是二进制目录,请使用以下用于设置 ant Hime,并将二进制目录添加到 env 路径中。In my case, I was setting my
ANT_HOME
variable, but had/bin/
appended for use in the system path - this home variable should not be the binary directory, use the following for setting an ant hime, and adding the binary directory to the env path.我在 Suse、SLES 11 上遇到了同样的问题。Hidayath 的回答 https://stackoverflow.com/a/4849302/1211900解决了它。
假设开箱即用的包存储库:
我@sles:~> sudo zypper 安装 xerces-j2-xml-apis
I had the same problem on Suse, SLES 11. Hidayath's answer https://stackoverflow.com/a/4849302/1211900 solved it.
Assuming out-of-the-box package repositories:
me@sles:~> sudo zypper install xerces-j2-xml-apis
我在 OS X 上遇到了完全相同的错误消息,但有人建议取消设置 ANT_HOME 并且这有效。
https://github.com/Homebrew/homebrew/issues/32851
I was having the exact same error message on OS X, but somebody suggested unsetting ANT_HOME and that worked.
https://github.com/Homebrew/homebrew/issues/32851
在我的例子中,“
lib
”文件夹包含所有jar,包括在
我复制的lib文件夹下,
因为运行“ant --execdebug”后,我发现ant命令正在寻找“1.9.1”下的“lib”文件夹。 6' 文件夹。
更改后 ant 命令开始正常工作。
In my case '
lib
' folder which has all jars includingwas under
I copied lib folder under
because after running 'ant --execdebug' i found ant commands are looking for 'lib' folder under '1.9.6' folder.
after that change ant commands started working fine.
运行
which ant
来了解ant_home
是否已设置。如果没有,请使用相应的路径运行以下命令来设置ant_home
:Run
which ant
to know if theant_home
set. If not please run below with your corresponding paths to setant_home
: