鹤壁建设网站推广/营销工具有哪些
在项目中有时候需要将Maven项目打包生成bat文件,单独运行。本文将详解利用maven-assembly-plugin插件实现bat文件打包。
1.首先看一下项目结构
2.配置pom.xml文件,在节点build中加入以下配置内容
src/main/java
**/*.xml
src/main/resources
src/main/resources/bin
src/main/resources/bin
true
bin
maven-jar-plugin
com.uih.anyi.mnis.drugbag.service.main.TestMain
true
${lib.output.dir}
false
.
properties/
maven-assembly-plugin
package
single
assembly.xml
2.assembly.xml文件内容
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
distribution
zip
${project.build.directory}/${project.build.finalName}.jar
/
${project.basedir}
/
README*
LICENSE*
NOTICE*
${project.build.outputDirectory}/bin/
/bin/
${project.build.outputDirectory}/properties/
/properties/
${project.build.outputDirectory}/db/
/db/
/${lib.output.dir}
runtime
3.编写bat批处理文件
@title Lachesis Synchronous_DrugBagRec_Datas %1
@echo %~dp0
echo off
rem Guess MNIS_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%MNIS_HOME%" == "" goto gotHome
set "MNIS_HOME=%CURRENT_DIR%"
if exist "%MNIS_HOME%\bin\run_midware.bat" goto okHome
set "MNIS_HOME=%~dp0.."
cd "%CURRENT_DIR%"
:gotHome
if exist "%MNIS_HOME%\bin\run_midware.bat" goto okHome
echo The MNIS_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome
if "%1" == "" goto startup
:startup
@set classpath=%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%MNIS_HOME%\lib;
java -Xms32m -Xmx128m -XX:MaxNewSize=32m -XX:MaxPermSize=128m -jar %MNIS_HOME%\${project.build.finalName}.${project.packaging} %1 &
echo on
:end
pause
4.选择项目,执行Maven Install
在target下会生成zip包,解压后,执行bin下的bat文件,就可以运行了。