使用 ant 命名空间/目录结构
我正在使用命令行在Linux 上使用ant。 我有一个使用 javac 的简单构建步骤。 这可以正确编译,但它会在构建下创建一个目录结构,就像我的命名空间一样。
即: ./build/com/crosse/samplespace/SampleProgram.class
如何将此输出放入一个目录(在其中更容易调用 java)。
我尝试过
<target name="output" depends="compile">
<copy todir="${output}">
<fileset dir="${build}" includes="**/*.class"/>
</copy>
</target>
,但在我的输出目录中重复了同样的事情。 如何使用 ant 将所有内容放入一个目录中?
或者,我如何使用 ant 步骤将另一个文件复制到该路径的根目录(apache commons 配置文件)?
编辑:这主要是一个便利因素,我厌倦了浏览相同的 3 个目录来运行我的程序。
I'm working with ant on linux using the command line. I've got a simple build step with javac. This compiles correctly but it creates a directory structure under build like my namespace.
ie: ./build/com/crosse/samplespace/SampleProgram.class
How can I get this output into one directory (where it's easier to call java on it).
I tried
<target name="output" depends="compile">
<copy todir="${output}">
<fileset dir="${build}" includes="**/*.class"/>
</copy>
</target>
but that repeats the same thing in my output directory. How can I use ant to get everything into a single directory?
Alternatively how could I use an ant step to copy another file into the root of that path (an apache commons configuration file)?
Edit: This is mainly a convenience factor, I get tired of navigating through the same 3 directories to run my program.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个包含所有文件(类和其他资源)的 jar 文件怎么样?
jar 还具有一个“默认”类,当用户双击它或使用
java -jar
调用它时,会执行该类的 main 方法。您可以使用 Ant jar 任务。
除此之外,保留目录结构(在 jar 之外)也很重要,否则 java 类加载器在必须加载这些类时会不高兴。 还是我问错了你的问题?
What about creating a jar file containing all your files (classes and other resources)?
A jar also has a 'default' class the main method of which gets executed when the user double clicks it or calls it using
java -jar <jar-file>
.You can use the Ant jar task.
Beside that, it is important that you keep your directory structure (outside a jar), otherwise the java class loader won't be happy when it has to load these classes. Or did I get your question wrong?
要回答您的问题,您可以使用 展平映射器,正如 Carej 指出的那样。 copy 任务甚至有一个快捷方式:
但是,我也不明白你希望以此完成什么。 java 运行时期望类文件位于镜像包结构的目录结构中。 将类文件复制到顶级目录将不起作用,除非类位于默认包中(
.java
文件中没有package
语句)。如果您想避免手动更改目录,您始终可以向 ant 构建文件添加一个目标,该目标使用适当的类路径和其他参数调用
java
任务。 例如:To answer your question, you would use a flatten mapper, as carej points out. The copy task even has a shortcut for it:
However, I also don't understand what you hope to accomplish with this. The java runtime expects class files to be in a directory structure that mirrors the package structure. Copying the class files to the top-level directory won't work, unless the classes are in the default package (there is no
package
statement in the.java
files).If you want to avoid having to manually change directories, you can always add a target to your ant build file that calls the
java
task with the appropriate classpath and other parameters. For example:您可以通过使用 flattenmapper 来完成您想做的事情,但我不知道您这样做的可能合理理由是什么。
You can accomplish what you want to do by using the flattenmapper but I'm at a loss to understand what possible valid reason you'd have for doing it.