zoukankan      html  css  js  c++  java
  • 详细解释 集成Maven Spring Mybatis项目包生成Bat文件

    有时在项目必须Maven项目包生成bat文件,长官一人。本文将解释的具体使用方法maven-assembly-plugin插件实现bat文件包。

    1.首先看一下项目结构


    2.配置pom.xml文件,在节点build中增加下面配置内容

    <span style="font-family:KaiTi_GB2312;font-size:18px;"><resources>
    			<resource>
    				<directory>src/main/java</directory>
    				<includes>
    					<include>**/*.xml</include>
    				</includes>
    			</resource>
    			<resource>
    				<directory>src/main/resources</directory>
    				<excludes>
    					<exclude>src/main/resources/bin</exclude>
    				</excludes>
    			</resource>
    			<resource>
    				<directory>src/main/resources/bin</directory>
    				<filtering>true</filtering>
    				<targetPath>bin</targetPath>
    			</resource>
    		</resources>
    
    		<plugins>
    			<plugin>
    				<artifactId>maven-jar-plugin</artifactId>
    				<configuration>
    					<archive>
    						<manifest>
    							<mainClass>com.uih.anyi.mnis.drugbag.service.main.TestMain</mainClass>
    							<addClasspath>true</addClasspath>
    							<classpathPrefix>${lib.output.dir}</classpathPrefix>
    							<useUniqueVersions>false</useUniqueVersions>
    						</manifest>
    						<manifestEntries>
    							<Class-Path>.</Class-Path>
    						</manifestEntries>
    					</archive>
    					<excludes>
    						<exclude>properties/</exclude>
    					</excludes>
    				</configuration>
    			</plugin>
    			<plugin>
    				<artifactId>maven-assembly-plugin</artifactId>
    				<executions>
    					<execution>
    						<phase>package</phase>
    						<goals>
    							<goal>single</goal>
    						</goals>
    					</execution>
    				</executions>
    				<configuration>
    					<descriptors>
    						<descriptor>assembly.xml</descriptor>
    					</descriptors>
    				</configuration>
    			</plugin>
    		</plugins>
    	</build></span>
    2.assembly.xml文件内容

    <span style="font-family:KaiTi_GB2312;font-size:18px;"><assembly
    	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">
    	<id>distribution</id>
    	<formats>
    		<format>zip</format>
    	</formats>
    	<files>
    		<file>
    			<source>${project.build.directory}/${project.build.finalName}.jar</source>
    			<outputDirectory>/</outputDirectory>
    		</file>
    	</files>
    	<fileSets>
    		<fileSet>
    			<directory>${project.basedir}</directory>
    			<outputDirectory>/</outputDirectory>
    			<includes>
    				<include>README*</include>
    				<include>LICENSE*</include>
    				<include>NOTICE*</include>
    			</includes>
    		</fileSet>
    		<!-- 相应src/java/resources/相关文件 -->
    		<fileSet>
    			<directory>${project.build.outputDirectory}/bin/</directory>
    			<outputDirectory>/bin/</outputDirectory>
    		</fileSet>
    		<fileSet>
    			<directory>${project.build.outputDirectory}/properties/</directory>
    			<outputDirectory>/properties/</outputDirectory>
    		</fileSet>
    		<fileSet>
    			<directory>${project.build.outputDirectory}/db/</directory>
    			<outputDirectory>/db/</outputDirectory>
    		</fileSet>
    	</fileSets>
    	<dependencySets>
    		<dependencySet>
    			<outputDirectory>/${lib.output.dir}</outputDirectory>
    			<scope>runtime</scope>
    		</dependencySet>
    	</dependencySets>
    </assembly></span>

    3.编写bat批处理文件

    <span style="font-family:KaiTi_GB2312;font-size:18px;">@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%in
    un_midware.bat" goto okHome
    set "MNIS_HOME=%~dp0.."
    cd "%CURRENT_DIR%"
    
    :gotHome
    if exist "%MNIS_HOME%in
    un_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%libdt.jar;%JAVA_HOME%lib	ools.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</span>

    4.选择项目,运行Maven Install

    在target下会生成zip包。解压后,执行bin下的bat文件,就能够执行了。



    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    Leetcode(680) ;验证回文字符串 Ⅱ
    mysql常用操作语句
    组合索引问题
    php生成一维码以及保存-转载
    php后台实现页面跳转的方法-转载
    php操作表格(写)
    虚拟机复制后上网冲突的问题
    centos下安装nginx(转载)
    虚拟机与宿主机可以互相ping通,但是外网不能
    防火墙设置:虚拟机ping不通主机,但是主机可以ping通虚拟机(转载)
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4753768.html
Copyright © 2011-2022 走看看