種常用的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"http://圖標路徑 } }
在配置文件中加入以上的文件之后就可以打包出來簡單的文件夾,文件夾肯定不是我們想要的東西。下一步我們來繼續講別的配置。
要打包成安裝程序的話我們有兩種方式,
"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小時內與您取得聯系。