Java Ant compile 不复制资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/804150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:38:59  来源:igfitidea点击:

Ant compile doesn't copy the resources

javaant

提问by Tomá? Linhart

I created my own build.xml which has:

我创建了自己的 build.xml,它具有:

<target name="compile">
    <mkdir dir="build"/> 
    <javac destdir="build"> 
        <src path="src"/> 
    </javac>
</target>

<target name="build" depends="compile">
    <mkdir dir="dist"/>
    <jar destfile="dist/app.jar" basedir="build" />
</target>

<target name="run" depends="compile">
    <java classname="webserver.Loader" classpath="build" fork="true" />      
</target>

It works great. When I call ant run so it compiles and runs my application, but my application has a package with icons and it isn't moved to a folder "build" so my application ends with an exception that it couldn't locate my icons. When I move them by myself then it works.

它工作得很好。当我调用 ant run 时,它会编译并运行我的应用程序,但我的应用程序有一个带有图标的包,并且它没有移动到“build”文件夹中,因此我的应用程序以无法找到我的图标的异常结束。当我自己移动它们时,它就起作用了。

I tried to use

我试着用

<copy todir="build/app/icons">
    <fileset dir="src/app/icons"/>
</copy>

It works, but I would like to do it without the copy command. Is there any parameter to javac? Or something else?

它有效,但我想在没有复制命令的情况下进行。javac 有参数吗?或者是其他东西?

Thank you for answer.

谢谢你的答案。

采纳答案by Mike Miller

Sorry, you will need to copy non-java files manually. Resources are technically not "source". The command-line javac will not copy resource files from your source directory to the output directory, neither will ant's javac task.

抱歉,您需要手动复制非 Java 文件。资源在技术上不是“来源”。命令行 javac 不会将资源文件从您的源目录复制到输出目录,ant 的 javac 任务也不会。

回答by jsight

No, there isn't. The copy task is the correct way to copy resources into your build folders.

不,没有。复制任务是将资源复制到构建文件夹中的正确方法。

回答by Chris Winters

There is no such parameter. You can copy all sorts of files between your directories with:

没有这样的参数。您可以使用以下命令在目录之间复制各种文件:

<copy todir="build">
    <fileset dir="src"
             includes="**/*.xml,**/*.properties,**/*.txt,**/*.ico" />
</copy>

回答by David Hopkins

You can do this using the filesetelement of the jartask instead of manually copying the files. For example:

您可以使用任务的fileset元素jar而不是手动复制文件来执行此操作。例如:

<jar destfile="dist/app.jar" basedir="build">
    <fileset dir="src" includes="app/icons/**" />
</jar>

This will copy everything in src/app/icons/to the app/iconspath in your .jar file.

这会将所有内容复制src/app/icons/app/icons.jar 文件中的路径中。