详解 集成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%\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</span>

4.选择项目,执行Maven Install

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

时间: 2024-08-27 22:36:16

详解 集成Maven Spring Mybatis项目打包生成Bat文件的相关文章

java项目打包生成MD5文件

之所以发出这篇博客,因为我前几天搞这个问题搞了几天,各种百度居然都没有找到相关的案例,虽然很简单的事件.可是百度博客上面居然都搜不到案例o(* ̄︶ ̄*)o觉得奇怪!!! 新总监来了,项目要上线,以前都没听旧总监提起要做什么打包生成MD5文件:一下子就蒙了o(* ̄︶ ̄*)o,主要原因还是因为我太菜O(∩_∩)O哈哈~ 因为项目要上线,很多工作要做,总监也忙的基本搭不上话,这几天会也没开,能完成那也是因为我对工作比较认真负责啊(手动滑稽): 以前没做过这样的事情,所以开始问其他朋友,都说直接上线就上

怎么将visual studio项目打包生成dll文件

1.打开电脑再打开visual studio软件,在软件里面新建一个项目,文件---->新建---->项目,打开新建项目窗口. 2.选择C#类工程,并为项目命名. 3.将类库文件class1重命名为其他名称,如这边的SQLDao(自行名),然后在弹出的确认窗口单击确定. 4.在类库文件中输入你所需要的内容. 5.右击--->生成,项目将编译生成DLL文件 6.打开项目所在的bin文件下的Debug文件夹,可以看到文件夹下已经生成我们所需要的DLL文件了, 原文地址:https://www

Maven+Spring+mybatis项目搭建

##倒腾了一个下午,龟速了下载了N多jar后,终于成功跑起## [前言]使用工具:开发工具使用的是sts(spring tool suite)点击打开链接, JDK 1.7,以及Mybatis generator点击打开链接 主要用来生成model.mapping和dao的,需要自己下载. [过程]1.建表:建立了一张User表,主要有id,name两个字段 2.修改generator.xml文件,具体如下 <?xml version="1.0" encoding="U

maven Spring MVC项目

IntelliJ IDEA上创建maven Spring MVC项目 各软件版本 利用maven骨架建立一个webapp 建立相应的目录 配置Maven和SpringMVC 配置Maven的pom.xml 配置web.xml 配置contextConfigLocation文件 配置log4j.properties controller和view的编写 servlet容器的配置和运行 配置本地的tomcat服务器 配置maven插件 运行第一个Spring MVC应用 目前java开发主流的IDE

用Eclipse 搭建一个Maven Spring SpringMVC 项目

1: 先创建一个maven web  项目: 可以参照之前的文章:  用Maven 创建一个 简单的 JavaWeb 项目 创建好之后的目录是这样的; 2: 先配置maven  修改pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="htt

maven spring mybatis配置注意点

以下对使用maven配置spring+mybatis项目时,完成基本的配置需要添加的一些信息进行说明.仅对mybatis部分进行列举. maven添加mybatis支持 <!-- mybatis核心包 –> <dependency>         <groupId>org.mybatis</groupId>         <artifactId>mybatis</artifactId>         <version>

mybatis学习笔记(六) -- maven+spring+mybatis从零开始搭建整合详细过程(下)

继续 mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上) 五.使用监听器启动Spring容器 1.修改pom.xml文件,添加Spring-web 2.修改web.xml,配置启动Spring容器 3.新建BookServer 4.新建BookServlet 5.修改ApplicationContext.xml 6.测试 继续!!! 五.使用监听器启动Spring容器 1.修改pom.xml,添加Spring-web包(注:上一篇中的pom

java实现的一个maven多模块项目自动生成工具

平时在做spring mvc web新项目时,都需要自己去搭建spring mvc的项目框架,包括基本pom 依赖引入,基本配置文件(web.xml,spring-mvc.xml,数据库配置文件等等),基础工具类引入.实际上对于所有spring mvc web项目,这些基础的配置和基础类都是通用的,都是可以复用,真正需要改变的无非是我们具体的业务逻辑.所以我们可以把这些通用的东西都做成基础模板,通过指定项目的groupId.artifactId.version就可以通过代码自动生成spring

将引用了第三方jar包的Java项目打包成jar文件的两种方法

方案一:用Eclipse自带的Export功能 步骤1:准备主清单文件 “MANIFEST.MF”, 由于是打包引用了第三方jar包的Java项目,故需要自定义配置文件MANIFEST.MF,在该项目下建立文件MANIFEST.MF,内容如下: Manifest-Version: 1.0 Class-Path: lib/commons-codec.jar lib/commons-httpclient-3.1.jar lib/commons-logging-1.1.jar lib/log4j-1.