为什么蚂蚁说" NoClassDefFound"当我的JAR是在类路径? [英] Why does Ant say "NoClassDefFound" when my JAR is on the classpath?

查看:141
本文介绍了为什么蚂蚁说" NoClassDefFound"当我的JAR是在类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java 1.6,Eclipse和蚂蚁。

I am using Java 1.6, Eclipse, and Ant.

下面是我创建一个jar文件并运行它的目标:

The following is my target for creating a jar file and running it:

    <!-- Settings -->
    <property file="build.properties" />
    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar" />
    </path>

    <!-- Compile -->
    <target name="compile">
        <mkdir dir="${classes.dir}" />
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
            <classpath refid="classpath" />
        </javac>
    </target>

    <!-- Package .jar -->
    <target name="jar">
        <mkdir dir="${jar.dir}" />
        <jar destfile="${jar.dir}/App.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="main.App" />
            </manifest>
        </jar>
    </target>

    <!-- Run .jar -->
    <target name="run">
        <java jar="${jar.dir}/App.jar" fork="true" />
    </target>

问题是,当我运行这个jar(通过Ant或命令行)我收到错误:

The problem is that when I run this jar (via Ant or command-line) I receive the error:

Exception in thread "main" java.lang.NoClassDefFoundError: net/xeoh/plugins/base/impl/PluginManagerFactory
     [java]     at plugins.PluginLoader.<clinit>(Unknown Source)

有些事情,可能是需要了解的:

Some things that might be useful to know:


  • 在打印我的类路径,这表明所有必要的jar文件
    那里;这也说明了类路径的Eclipse的GUI版本。

  • When I print my classpath, it shows that all the requisite JARs are there; it also shows up the Eclipse's GUI version of the class path.

我试图清理项目(包括通过Eclipse和Ant)无济于事。

I have tried cleaning the project (both via Eclipse and Ant) to no avail.

该库的.jar,这似乎是缺少的是不会在一个.jar一个.jar(这似乎是一个常见的​​问题)。

The library .jar that seems to be missing is not a .jar in a .jar (which seems to be a common problem).

这是唯一的错误。其他类似乎找到库好吗...

This is the only error. Other classes seem to find the library alright...

推荐答案

您已经设置了编译类路径,但App.jar不包括你的库(只有你的类编译)或清单类路径。

You've set the compile classpath but the App.jar does not include your libs (only the classes you compiled) or a manifest classpath.

您需要做到以下几点:

<target name="jar">
    <mkdir dir="${jar.dir}" />
    <manifestclasspath property="manifest.classpath"
                       jarfile="${jar.dir}/App.jar">
      <classpath refid="classpath" />
    </manifestclasspath>
    <jar destfile="${jar.dir}/App.jar" basedir="${classes.dir}">
        <manifest>
            <attribute name="Main-Class" value="main.App" />
            <attribute name="Class-Path" value="${manifest.classpath}" />.
        </manifest>
    </jar>
</target>

又见蚂蚁manifestclasspath任务

这篇关于为什么蚂蚁说&QUOT; NoClassDefFound&QUOT;当我的JAR是在类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆