导出到JAR,不包括一些其他文件

时间:2014-02-17 16:01:07

标签: java eclipse ant

我有将类构建到bin目录的项目。我有额外的ANT构建器,它获取bin目录的内容并放入proj_hug.jar。但bin文件夹包含*.properties文件,我不会将其包含在JAR中。如何解决这个问题?

ANT脚本:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project proj with libraries in sub-folder">
    <!--this file was created by Eclipse Runnable JAR Export Wizard-->
    <!--ANT 1.7 is required                                        -->
    <target name="create_run_jar">
        <jar destfile="C:/Projects/proj/JAR/proj_hug.jar">
            <manifest>
                <attribute name="Main-Class" value="hug.projhugHandler"/>
                <attribute name="Class-Path" value=". proj_hug_lib/RXTXcomm.jar proj_hug_lib/log4j.jar proj_hug_lib/hug.jar proj_hug_lib/commons-codec-1.5.jar"/>
            </manifest>
            <fileset dir="C:/Projects/proj/bin">
            </fileset>
        </jar>
        <delete dir="C:/Projects/proj/JAR/proj_hug_lib"/>
        <mkdir dir="C:/Projects/proj/JAR/proj_hug_lib"/>
        <copy file="C:/Projects/proj/RXTXcomm.jar" todir="C:/Projects/proj/JAR/proj_hug_lib"/>
        <copy file="C:/Projects/proj/log4j.jar" todir="C:/Projects/proj/JAR/proj_hug_lib"/>
        <copy file="C:/Projects/proj/hug.jar" todir="C:/Projects/proj/JAR/proj_hug_lib"/>
        <copy file="C:/Projects/proj/commons-codec-1.5.jar" todir="C:/Projects/proj/JAR/proj_hug_lib"/>

    </target>
</project>

我在<fileset>中添加了:

<fileset dir="C:/Projects/proj/bin">
        <include name="*.class"/>
        <exclude name="*.properties*"/>
</fileset>

但是这会让事情变得更糟 - 我的JAR中没有类文件和任何属性文件。

UPD:

如果我这样做:

<fileset dir="C:/Projects/proj/bin">
        <include name="**/*.class"/>
        <exclude name="**/*.properties*"/>
</fileset>

我在jar文件中只有META-INF。

如果我喜欢:

 <fileset dir="C:/Projects/proj/bin">
            <include name="**/*.class"/>
    </fileset>

我在jar文件中只有META-INF。

如果我喜欢:

<fileset dir="C:/Projects/proj/bin">
        <exclude name="**/*.properties*"/>
</fileset>

我在jar中有空包目录和META-INF。

1 个答案:

答案 0 :(得分:1)

确保您有javac任务将代码编译到<project home>/bin目录。

将您的fileset更改为:

<fileset dir="C:/Projects/proj/bin">
    <include name="**/*.class"/>
    <exclude name="**/*.properties*"/>
</fileset>