我的ant配置有什么问题?

发布于 2024-08-22 19:07:44 字数 1960 浏览 10 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

清风夜微凉 2024-08-29 19:07:44

我刚刚在 Fedora 18 上遇到了类似的问题。

长话短说,运行:

sudo mkdir /usr/lib/java-1.7.0 /usr/share/java-1.7.0

显然,这个问题特定于 java-1.7.0-openjdk 因为类似 empty所有其他 JDK 版本的目录均已存在。


详情

运行ant后出现单行错误:

Error: Could not find or load main class org.apache.tools.ant.launch.Launcher

问题出在/usr/share/java-utils/java-functions脚本中它尝试设置 JAVAVER_JNIDIR/JAVAVER_LIBDIR 变量来引用上面的目录。由于错误消息重定向到 stdout 不适当,某些变量得到了如下分配:

LOCALCLASSPATH='/usr/bin/build-classpath: error: JAVAVER_JNIDIR /usr/lib/java-1.7.0 does not exist or is not a directory'

根据所有其他 java 版本设置的约定创建目录是最干净的解决方案。

I've just met similar issue on Fedora 18.

To make long story short, run:

sudo mkdir /usr/lib/java-1.7.0 /usr/share/java-1.7.0

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:

Error: Could not find or load main class org.apache.tools.ant.launch.Launcher

The problem was somewhere in /usr/share/java-utils/java-functions script which tried to set JAVAVER_JNIDIR/JAVAVER_LIBDIR variables to refer to the directories above. Due to inappropriate error message redirection to stdout, some variables got assignments like:

LOCALCLASSPATH='/usr/bin/build-classpath: error: JAVAVER_JNIDIR /usr/lib/java-1.7.0 does not exist or is not a directory'

Creating the directories according to the convention set by all other java versions is the cleanest solution.

愿与i 2024-08-29 19:07:44
sudo mkdir /usr/lib/java-1.7.0 /usr/share/java-1.7.0

我通过下载 tar 文件并将其放在 /opt 中来安装 sun java 1.7.x。因为我没有执行 yum install,所以没有创建这些目录。我的 JAVA_HOME 设置为:

$ echo $JAVA_HOME/
/opt/jdk1.7.0_03/

正如其他人所说,运行以下命令提供了非常有用的调试:

ant --execdebug
sudo mkdir /usr/lib/java-1.7.0 /usr/share/java-1.7.0

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:

$ echo $JAVA_HOME/
/opt/jdk1.7.0_03/

As someone else said, running the following provided very useful debug:

ant --execdebug
野味少女 2024-08-29 19:07:44

我认为 ANT_HOME 应该设置为“/usr/bin/ant”。我有这样的配置(CENTOS 5)。

我在“/etc/profile.d”下的 sh 脚本有这样的配置:

export JAVA_HOME="/usr/local/java";
export ANT_HOME="/usr/local/ant";

我希望它对你有帮助。

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.:

export JAVA_HOME="/usr/local/java";
export ANT_HOME="/usr/local/ant";

I hope it helps you.

蓬勃野心 2024-08-29 19:07:44

我遇到了类似的问题,但以下内容为我解决了:

sudo yum install xml-commons-apis

I had a similar problem but the following fixed it for me:

sudo yum install xml-commons-apis
下壹個目標 2024-08-29 19:07:44

我今天有同样的错误消息,但由不同的原因触发。

就我而言,更新到 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.

望她远 2024-08-29 19:07:44

我在 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 的软链接,因此我采取了以下步骤:

  1. 为当前版本的 jdk (jdk1.6.0_32) 创建一个新目录,
  2. 复制来自openjdk 的目录复制到新目录
    # cp -av java-1.6.0-openjdk-1.6.0.0.x86_64/* jdk1.6.0_32/
  3. 更正所有内容,以便它们指向oracle 的 jar,例如:
    # 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 and xml-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:

  1. create a new directory for current version of jdk (jdk1.6.0_32)
  2. copy all links from the openjdk's directory to the new directory
    # cp -av java-1.6.0-openjdk-1.6.0.0.x86_64/* jdk1.6.0_32/
  3. correct all of them so as they are pointing on oracle's jars, example:
    # 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.

那一片橙海, 2024-08-29 19:07:44

尝试安装xerces-j2-xml-apis

Try installing xerces-j2-xml-apis

z祗昰~ 2024-08-29 19:07:44

就我而言,我设置了 ANT_HOME 变量,但附加了 /bin/ 以便在系统路径中使用 - 此主变量不应是二进制目录,请使用以下用于设置 ant Hime,并将二进制目录添加到 env 路径中。

export ANT_HOME=/opt/apache-ant-1.9.4
export PATH=$ANT_HOME/bin:$PATH

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.

export ANT_HOME=/opt/apache-ant-1.9.4
export PATH=$ANT_HOME/bin:$PATH
任性一次 2024-08-29 19:07:44

我在 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

萌︼了一个春 2024-08-29 19:07:44

我在 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

挽梦忆笙歌 2024-08-29 19:07:44

在我的例子中,“lib”文件夹包含所有jar,包括

ant-launcher.jar

/usr/local/Cellar/ant/1.9.6/libexec/ 

我复制的lib文件夹下,

/usr/local/Cellar/ant/1.9.6/

因为运行“ant --execdebug”后,我发现ant命令正在寻找“1.9.1”下的“lib”文件夹。 6' 文件夹。

更改后 ant 命令开始正常工作。

In my case 'lib' folder which has all jars including

ant-launcher.jar

was under

/usr/local/Cellar/ant/1.9.6/libexec/ 

I copied lib folder under

/usr/local/Cellar/ant/1.9.6/

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.

迷鸟归林 2024-08-29 19:07:44

运行 which ant 来了解 ant_home 是否已设置。如果没有,请使用相应的路径运行以下命令来设置 ant_home

export ANT_HOME=/ade_autofs/gd29_3rdparty/ANT_1.7.1_GENERIC.rdd/080925/ant 
export PATH=$ANT_HOME/bin:${PATH}

Run which ant to know if the ant_home set. If not please run below with your corresponding paths to set ant_home:

export ANT_HOME=/ade_autofs/gd29_3rdparty/ANT_1.7.1_GENERIC.rdd/080925/ant 
export PATH=$ANT_HOME/bin:${PATH}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文