种常用的maven打包插件总结:
一、自带插件:
maven自带的核心插件为Build plugins和Reporting plugins。
mvn compile编译源码实际上就利用到了maven-compiler-plugin,其他phase也类似用到了相应的插件
关于maven自带的核心插件见:http://maven.apache.org/plugins/index.html
核心插件 maven-compiler-plugin
参考地址 http://maven.apache.org/plugins/maven-compiler-plugin/
从3.0版本开始,编译工具默认使用的是 javax.tools.JavaCompiler(从JDK 1.6开始) 如果要强制使用javac来进行编译,需要添加参数forceJavacCompilerUse
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<encoding>utf-8</encoding>
<source>1.7</source>
<!-- 默认1.5 -->
<target>1.7</target>
<!-- 默认1.5 -->
<compilerArgs>
<!-- 传递编译参数 -->
<arg>-verbose</arg>
<arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
<fork>true</fork>
<!-- 配置编译内存参数 -->
<meminitial>128m</meminitial>
<!-- 初始内存 -->
<maxmem>512m</maxmem>
<!-- 最大内存 -->
<executable>${JAVA_1_4_HOME}/bin/javac</executable>
<!-- 指定编译的java库 -->
<compilerVersion>1.3</compilerVersion>
<!-- 指定编译版本 -->
</configuration>
</plugin>
配置source 和target时,也可以这样配置 实际上这是javac指令可以接受的参数
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
二、直接打成可执行的jar包。
这种打包方式比较粗暴,将应用的依赖包和程序包打成一个全量包。包会相对较大,但是好处也很明显,不用管依赖包。所以这种方式只适用于比较小的项目,比如搭建微服务这种方式可以适用。
附上关键的服务器执行代码
java -jar dataCleaner.jar 1>/home/credit/app/tracefile 2>/home/credit/app/errorfile &
说明: 最后面的& 表明后台执行。
1> 将运行日志输出到tracefile
2> 将错误日志输出到errorfile
具体参数很多,参考官网页面
官网页面 http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
还一种方式,可以使用spring-boot的打包插件进行打包。一般是跟spring boot一起使用的,但是也可以单独利用出来打成可执行的整包。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.5.RELEASE</version>
<configuration>
<mainClass>com.ftoul.dataCleaner.DataCleanServiceProvider</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
补充一下,还有一个shade插件也是比较常用的打fat jar包的方式
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.sonatype.haven.ExodusCli</Main-Class>
<Build-Number>123</Build-Number>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
三 将依赖包与代码包分开打包
这种打包方式更普遍适用。毕竟依赖的jar包在项目发展中变动会相对较小。一般可配合maven-dependency-plugin 和 maven-jar-plugin 两个插件打包。前者负责依赖包,后者负责程序包。
另外,附上服务器可用的执行脚本。
more runapp.sh
#!/bin/sh
#执行jar包
RUN_LIBS=""
#依赖jar包
SUPPORT_LIBS=""
RUN_LIB_PATH="$HOME/app/lib"
SUPPORT_LIB_PATH="$HOME/app/support"
#加载程序包
for i in ${RUN_LIB_PATH}/* ; do
RUN_LIBS=${RUN_LIBS}:$i
done
#加载依赖包
for i in ${SUPPORT_LIB_PATH}/* ; do
SUPPORT_LIBS=${SUPPORT_LIBS}:$i
done
#整合classpath
CLASSPATH=${RUN_LIBS}:${SUPPORT_LIBS}
export CLASSPATH
#调用java指令执行。-D输入参数 java中可以用 System.getProperties读取。同时指定执行入口类 SpringBootApplication 这是一个典型的Springboot的执行方式。
java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=27899,suspend=n -cp $CLASSPATH -Dspring.profiles.active=prod com.app.SpringBootApplication -D
user.timezone=GMT+08 1>/home/credit/ftoulcloud/bin/tracefile 2>/home/credit/ftoulcloud/bin/errorfile &
echo Start App Success!
assembly官网的其他几个示例使用项目的依赖包进行打包
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>src-dependencies</id>
<phase>package</phase>
<goals>
<!-- use copy-dependencies instead if you don't want to explode the sources -->
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
将指定的包打入依赖包
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<destFileName>optional-new-name.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>
</plugins>
</build>
一个可用的示例
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- <version>2.10</version> -->
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>export</outputDirectory> <!-- 将依赖包放入export文件夹 -->
<excludeTransitive>false</excludeTransitive>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
四、maven-jar-plugin 将指定的一些文件打包成jar包
这个比较简单。就将指定的文件打成jar包
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration> <!-- manifest配置信息 主要是可以配置主执行类。有主执行类,可以用java-jar直接执行。没有的话就需要指定执行类 -->
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>support/</classpathPrefix>
<mainClass>com.myapp.MyAppApplication</mainClass>
<!-- 可以按上面的方式自己配置,也可以指定MF文件打包。 -->
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>myapp1-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>myapp</classifier>
<includes>
<include>com/myapp/**</include>
<include>mybatis/**</include>
<include>templates/**</include>
<include>*.properties</include>
<include>dubbo.xml</include>
</includes>
</configuration>
</execution>
<execution>
<id>myapp2-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>myapp2</classifier>
<includes>
<include>com/myapp2/crawler/*</include>
<include>com/myapp2/crawler/*</include>
<include>com/myapp2/utils/**</include>
<include>log4j.properties</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
五、其他丰富的三方插件
PMD打包插件。 PMD一个很好用的静态代码检查插件, eclipse可以直接安装插件使用
生成PMD报告
http://maven.apache.org/plugins/maven-pmd-plugin/
只能用于3.3.3以后的maven版本
分析JSP页面
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<language>jsp</language>
<rulesets>
<ruleset>jsp-basic</ruleset>
</rulesets>
<includes>
<include>**/*.jsp</include>
</includes>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/webapp</compileSourceRoot>
</compileSourceRoots>
</configuration>
</plugin>
</plugins>
</reporting>
分析JS
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<language>javascript</language>
<rulesets>
<ruleset>ecmascript-basic</ruleset>
<ruleset>ecmascript-braces</ruleset>
<ruleset>ecmascript-unnecessary</ruleset>
</rulesets>
<includes>
<include>**/*.js</include>
</includes>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/javascript</compileSourceRoot>
</compileSourceRoots>
</configuration>
</plugin>
</plugins>
</reporting>
代码非法检查
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
制定JDK
<reporting>
<plugins>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<targetJdk>1.6</targetJdk>
</configuration>
</plugin>
</plugins>
</reporting>
删除PMD报告
<reporting>
<plugins>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<reportSets>
<reportSet>
<reports>
<report>pmd</report>
<report>cpd</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
没事可以经常去官网转转,时不时有些新的打包插件出来。 比如PDF插件 GPG签名插件 TOMCAT插件 JETTY插件 等。 好多好多。用时慢慢去了解。
nes9X EX是一款高级的开源超级任天堂模拟器,小编这次给大家提供的是Snes9X EX安卓汉化版,由大神星辰汉化,基本已经完全汉化完成,使用起来没有任何障碍。这款模拟器之前是PC上的,现在这个模拟器被移植到安卓平台上了。可用来模拟重装机兵2、重装机兵R、其他SFC经典游戏ROM,基于Snes9x 1.53而开发,兼容几乎所有的SFC游戏ROM。模拟器内包含了一个名为Bio Worm的公共域名版权的游戏。其他Rom必须由用户自己寻找获取。你只需要将获取到的游戏放置于你的内部存储或者SD卡之上,并在应用内浏览它们就可以开始游戏了。ROM可以是.smc或者.sfc格式,也可以封装于.zip文件中。小编推荐大家使用1GHz+以上的设备来进行模拟游戏,可以非常的流畅的运行!
下载地址:http://www.32r.com/app/86709.html
1、精确的模拟和类似PC一样的兼容性。
2、完美的44KHz的立体声。
3、支持.smc, .sfc, .fig, 和 .1等格式的游戏,能够识别zip文件中的游戏。
4、支持屏幕控制开火,也支持屏幕外光标按钮。
4、可配置的屏幕多点触控控制和键盘的支持。
5、多人游戏功能。
6、备份与存储功能。
7、横向与纵向支持。
1、准确的仿真和高兼容率,利用Snes9x 1.43或1.53的引擎。
2、支持自动保存及存档备份,自带十个用于手动保存的位置。
3、支持smc、sfc、fig等游戏格式,还可以选择.zip文件。
4、超级示波器以及触摸屏操作支持。
5、支持电脑鼠标输入支持。
6、可配置的屏幕上多点触摸控件和键盘支持(需要Android 2.1+才能实现多点触摸)
如何使用
来源:https://www.php.cn/div-tutorial-411690.html
builder的使用和配置都是很简单的
builder配置有两种方式
package.json中直接配置使用(比较常用,我们下面着重来讲这个)
指定electron-builder.yml文件
demo地址会在文章末尾给出(demo项目中electron使用得是V2.0.7版本,目前更高得是2.0.8版本)。
下面是一个简单的package.js中带注释的配置
"build": { // 这里是electron-builder的配置 "productName":"xxxx",//项目名 这也是生成的exe文件的前缀名 "appId": "com.xxx.xxxxx",//包名 "copyright":"xxxx",//版权 信息 "directories": { // 输出文件夹 "output": "build" }, // windows相关的配置 "win": { "icon": "xxx/icon.ico"//图标路径 } }
在配置文件中加入以上的文件之后就可以打包出来简单的文件夹,文件夹肯定不是我们想要的东西。下一步我们来继续讲别的配置。
要打包成安装程序的话我们有两种方式,
"win": { // 更改build下选项 "icon": "build/icons/aims.ico", "target": [ { "target": "nsis" // 我们要的目标安装包 } ] },
其他平台配置
"dmg": { // macOSdmg "contents": [ ... ] }, "mac": { // mac "icon": "build/icons/icon.icns" }, "linux": { // linux "icon": "build/icons" }
nsis配置
这个要详细的讲一下,这个nsis的配置指的是安装过程的配置,其实还是很重要的,如果不配置nsis那么应用程序就会自动的安装在C盘。没有用户选择的余地,这样肯定是不行的
关于nsis的配置是在build中nsis这个选项中进行配置,下面是部分nsis配置
"nsis": { "oneClick": false, // 是否一键安装 "allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。 "allowToChangeInstallationDirectory": true, // 允许修改安装目录 "installerIcon": "./build/icons/aaa.ico",// 安装图标 "uninstallerIcon": "./build/icons/bbb.ico",//卸载图标 "installerHeaderIcon": "./build/icons/aaa.ico", // 安装时头部图标 "createDesktopShortcut": true, // 创建桌面图标 "createStartMenuShortcut": true,// 创建开始菜单图标 "shortcutName": "xxxx", // 图标名称 "include": "build/script/installer.nsh", // 包含的自定义nsis脚本 这个对于构建需求严格得安装过程相当有用。 "script" : "build/script/installer.nsh" // NSIS脚本的路径,用于自定义安装程序。 默认为build / installer.nsi },
关于include 和 script 到底选择哪一个 ?
在对个性化安装过程需求并不复杂,只是需要修改一下安装位置,卸载提示等等的简单操作建议使用include配置,如果你需要炫酷的安装过程,建议使用script进行完全自定义。
NSIS对于处理安装包这种东西,功能非常的强大。但是学习起来并不比一门高级语言要容易。其中的奥秘还要各位大佬自行探索
这里上一些学习资源
主要是windows中64和32位的配置
CLI参数
electron-builder --ia32 // 32位 electron-builder // 64位(默认) nsis中配置 "win": { "icon": "build/icons/aims.ico", "target": [ { "target": "nsis", "arch": [ // 这个意思是打出来32 bit + 64 bit的包,但是要注意:这样打包出来的安装包体积比较大,所以建议直接打32的安装包。 "x64", "ia32" ] } ] }
更新配置
下面这个是给更新用的配置,主要是为了生成lastest.yaml配置文件
"publish": [ { "provider": "generic", // 服务器提供商 也可以是GitHub等等 "url": "http://xxxxx/" // 服务器地址 } ],
完整配置
基本上可用的完整的配置
"build": { "productName":"xxxx",//项目名 这也是生成的exe文件的前缀名 "appId": "com.leon.xxxxx",//包名 "copyright":"xxxx",//版权 信息 "directories": { // 输出文件夹 "output": "build" }, "nsis": { "oneClick": false, // 是否一键安装 "allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。 "allowToChangeInstallationDirectory": true, // 允许修改安装目录 "installerIcon": "./build/icons/aaa.ico",// 安装图标 "uninstallerIcon": "./build/icons/bbb.ico",//卸载图标 "installerHeaderIcon": "./build/icons/aaa.ico", // 安装时头部图标 "createDesktopShortcut": true, // 创建桌面图标 "createStartMenuShortcut": true,// 创建开始菜单图标 "shortcutName": "xxxx", // 图标名称 "include": "build/script/installer.nsh", // 包含的自定义nsis脚本 }, "publish": [ { "provider": "generic", // 服务器提供商 也可以是GitHub等等 "url": "http://xxxxx/" // 服务器地址 } ], "files": [ "dist/electron/**/*" ], "dmg": { "contents": [ { "x": 410, "y": 150, "type": "link", "path": "/Applications" }, { "x": 130, "y": 150, "type": "file" } ] }, "mac": { "icon": "build/icons/icon.icns" }, "win": { "icon": "build/icons/aims.ico", "target": [ { "target": "nsis", "arch": [ "ia32" ] } ] }, "linux": { "icon": "build/icons" } }
命令行参数(CLI)
Commands(命令):
electron-builder build 构建命名 [default]
electron-builder install-app-deps 下载app依赖
electron-builder node-gyp-rebuild 重建自己的本机代码
electron-builder create-self-signed-cert 为Windows应用程序创建自签名代码签名证书
electron-builder start 使用electronic-webpack在开发模式下运行应用程序(须臾要electron-webpack模块支持)
Building(构建参数):
--mac, -m, -o, --macos Build for macOS, [array] --linux, -l Build for Linux [array] --win, -w, --windows Build for Windows [array] --x64 Build for x64 (64位安装包) [boolean] --ia32 Build for ia32(32位安装包) [boolean] --armv7l Build for armv7l [boolean] --arm64 Build for arm64 [boolean] --dir Build unpacked dir. Useful to test. [boolean] --prepackaged, --pd 预打包应用程序的路径(以可分发的格式打包) --projectDir, --project 项目目录的路径。 默认为当前工作目录。 --config, -c 配置文件路径。 默认为`electron-builder.yml`(或`js`,或`js5`)
Publishing(发布):
--publish, -p 发布到GitHub Releases [choices: "onTag", "onTagOrDraft", "always", "never", undefined] <font color="red">Deprecated(废弃):</font> --draft 请改为在GitHub发布选项中设置releaseType [boolean] --prerelease 请改为在GitHub发布选项中设置releaseType [boolean] --platform 目标平台 (请更改为选项 --mac, --win or --linux) [choices: "mac", "win", "linux", "darwin", "win32", "all", undefined] --arch 目标arch (请更改为选项 --x64 or --ia32) [choices: "ia32", "x64", "armv7l", "arm64", "all", undefined] Other(其他): --help Show help [boolean] --version Show version number [boolean] Examples(例子): electron-builder -mwl 为macOS,Windows和Linux构建(同时构建) electron-builder --linux deb tar.xz 为Linux构建deb和tar.xz electron-builder -c.extraMetadata.foo=bar 将package.js属性`foo`设置为`bar` electron-builder --config.nsis.unicode=false 为NSIS配置unicode选项
TargetConfiguration(构建目标配置):
*请认真填写需求信息,我们会在24小时内与您取得联系。