如何自动创建批处理/shell 脚本来运行 Java 控制台应用程序? [英] How to automatically create batch / shell scripts to run a Java console application?
问题描述
我有一个 Java 命令行应用程序,我想创建一个 Ant* 构建脚本,该脚本将创建成功运行应用程序所需的所有批处理/shell 脚本,包括所有类路径变量.我需要它执行以下操作:
I have a Java command-line application, and would like to create an Ant* build script that will create all the required batch/shell scripts to run the application successfully including all the classpath variables. I need it to do the following:
- 为 Linux/Unix 创建一个 shell 脚本文件,为 Windows/DOS 创建一个批处理文件
- 添加所有类路径依赖项(来自 Maven 或简单地使用 Eclipse 中的构建路径)
- 添加任何必要的样板 sh/bat 代码以运行(ENV 变量、JAVA_HOME 等)
我在此处只找到了部分答案.
I found only a partial answer here.
但我还没有发现任何可以完成每个构建都涉及的基本而微不足道的任务.
But I haven't found anything that does this basic and trivial task that every build involves.
免责声明 - 最初的问题是 Ant/Maven,但我更愿意看看它是否可以在 Ant 中完成.
Disclaimer - the original question was Ant/Maven, but I would prefer to see if it can be done in Ant.
推荐答案
在 Maven 中,最好的解决方案是 maven-appassembler-plugin 处理 shell 脚本/批处理文件的创建.结合 maven-assembly,您可以创建 tar.gz 或 zip 存档,其中包含所需的一切.
In Maven the best solution for this is the maven-appassembler-plugin which handles the creation of a shell script / batch file. In combination with maven-assembly you can create a tar.gz or zip archive which contains everything which is needed.
这篇关于如何自动创建批处理/shell 脚本来运行 Java 控制台应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!