简体   繁体   English

为Maven项目创建一个可执行的.bat文件

[英]Create an executable .bat file for a Maven project

I have a maven project which runs on command line by running a script. 我有一个Maven项目,该项目通过运行脚本在命令行上运行。 I want to distribute it on both Windows and Linux. 我想在Windows和Linux上分发它。 I have searched all the related posts but I didn't fully understood how I can create a .bat file for windows. 我搜索了所有相关文章,但是我不完全了解如何为Windows创建.bat文件。

All my dependencies are copied to a folder named mavenLib and a jar file gets created in the target folder in ubuntu using: 我所有的依赖项都复制到一个名为mavenLib的文件夹中,并使用以下命令在ubuntu的目标文件夹中创建一个jar文件:

export CLASSPATH=`ls -1 target/mavenLib/* | tr '\n' ':'`target/ClientPortfolioCreator-0.0.1-SNAPSHOT.jar

What is the alternative in windows? Windows中的替代方法是什么?

I suggest you use a maven plugin called the appassembler-maven-plugin . 我建议您使用一个名为appassembler-maven-plugin的maven插件 This plugin generates Unix and Windows scripts and also copies all necessary dependencies in a local folder. 该插件生成Unix和Windows脚本,还将所有必要的依赖项复制到本地文件夹中。

The plugin's basic usage is as follows: 该插件的基本用法如下:

In the build section of the pom.xml , add the following configuration according to your requirements. pom.xml的build部分中,根据需要添加以下配置。

<build>  
  <plugins>  
    <plugin> 
      <groupId>org.codehaus.mojo</groupId>  
      <artifactId>appassembler-maven-plugin</artifactId>  
      <configuration>
       <programs>  
         <program>  
            <mainClass>your.package.YourMainClass</mainClass>
            <name>TheScriptName</name>
         </program>
       </programs>   
      </configuration>  
    </plugin>  
 </plugins>  

Then execute: 然后执行:

mvn package appassembler:assemble

And that's all, the plugin output is located by default in target/appassembler 就是这样,插件输出默认位于target / appassembler中

For more detailed information, go to the plugin homepage . 有关更多详细信息,请转到插件主页

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM