Ant 编译的类不包括在生成的Jar中

Ant 编译的类不包括在生成的Jar中,ant,build,Ant,Build,我正在使用ant构建脚本创建一个jar包。问题是生成的.jar文件中不包括.class文件。我还尝试了{build.dest}来制作jar,但没有效果 我需要的其余所有文件都在.jar文件中 这是我的构建脚本 <?xml version="1.0"?> <project name="TaskNodeBundle" default="all" basedir="."> <!-- Sets variables which can later be used.

我正在使用ant构建脚本创建一个jar包。问题是生成的.jar文件中不包括.class文件。我还尝试了{build.dest}来制作jar,但没有效果

我需要的其余所有文件都在.jar文件中

这是我的构建脚本

<?xml version="1.0"?>

<project name="TaskNodeBundle" default="all" basedir=".">
    <!-- Sets variables which can later be used. -->
    <!-- The value of a property is accessed via ${} -->
    <property name="bundlename" value="task-node-bundle" />
    <property name="src.dir" location="../src" />
    <property name="lib.dir" location="../lib" />
    <property name="build.dir" location="/buildoutput" />
    <property name="build.dest" location="../build/dest" />


    <!--
        Create a classpath container which can be later used in the ant task
    -->
    <path id="classpath">
        <fileset dir="${lib.dir}/">
            <include name="*.jar" />
        </fileset>
    </path>

    <target name="clean">
        <delete dir="${build.dir}" />
        <delete dir="${build.dest}" />
    </target>

    <!-- Deletes the existing build directory -->
    <target name="mkdir" depends="clean">
        <mkdir dir="${build.dest}"/>
    </target>


    <!-- Compiles the java code -->
    <target name="compile" depends="mkdir">
        <javac srcdir="${src.dir}" destdir="${build.dest}" classpathref="classpath" />
    </target>

    <target name="package-bundle" depends="compile" description="Generates the bundle" >
        <jar destfile="${build.dest}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
            <fileset dir="${src.dir}">
                <include name="**/**.class" />
                <include name="**/**.properties"/>
                <include name="/META-INF/**.*" />
                <include name="/META-INF/spring/**.*" />
            </fileset>
        </jar>
    </target>

    <target name="all" depends="package-bundle">
    </target>

</project>

首先,您所说的“在制作jar时尝试了{build.dest}”是什么意思

不管怎样,您需要查看构建的这一部分:

<jar destfile="${build.dest}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
    <fileset dir="${src.dir}">
        <include name="**/**.class" />
        <include name="**/**.properties"/>
        <include name="/META-INF/**.*" />
        <include name="/META-INF/spring/**.*" />
    </fileset>
</jar>
然后呢,

<jar destfile="${dist.dir}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
    <fileset dir="${build.dest}">
        <include name="**/*.class" />
    </fileset>
    <fileset dir="${src.dir}">
        <include name="**/*.properties"/>
        <include name="/META-INF/**/*.*" />
        <include name="/META-INF/spring/**/*.*" />
    </fileset>
</jar>


嘿,我看到了你的编辑。当然,您可以使用${build.dest}来存储jar文件;但是,作为一种常见做法,我建议将编译的类文件和生成的jar文件放在不同的驱动器中。例如,Netbeans项目的类文件位于
project/build/classes
中,而生成的jar文件位于
project/dist
中。非常感谢。我真的很感激
<jar destfile="${dist.dir}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
    <fileset dir="${build.dest}">
        <include name="**/*.class" />
    </fileset>
    <fileset dir="${src.dir}">
        <include name="**/*.properties"/>
        <include name="/META-INF/**/*.*" />
        <include name="/META-INF/spring/**/*.*" />
    </fileset>
</jar>