[TOC]
# IDEA打包
打包自定義工具類文件






然后`java -jar xx.jar`
# maven war包
注意:需要在pom.xml中注明打包方式為war

點擊界面最右側的選項:Maven Projects -> 雙擊package

war包存在目錄結構

測試
`java -jar xx.jar`
測試成功!(該war包內含tomcat)
# maven-assembly-plugin
在pom.xml中加入一個插件來打包,如下:
~~~
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.yj.spark.TestSpark</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
~~~
這種方式是通過maven命令來打包的:

或者 `mvn assembly:assembly`
見名知意,其中 spark-1.0.jar 只有代碼,無依賴,而 spark-1.0-jar-with-dependencies.jar則包含所有jar包

# 詳解
簡單的說,maven-assembly-plugin 就是用來幫助打包用的,比如說打出一個什么類型的包,包里包括哪些內容等等。
目前至少支持以下打包類型:
* zip
* tar
* tar.gz
* tar.bz2
* jar
* dir
* war
默認情況下,打jar包時,只有在類路徑上的文件資源會被打包到jar中,并且文件名是${artifactId}-${version}.jar,下面看看怎么用maven-assembly-plugin插件來定制化打包
首先需要添加插件聲明:
~~~
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
~~~
默認情況下,maven-assembly-plugin內置了幾個可以用的assembly descriptor:
* bin : 類似于默認打包,會將bin目錄下的文件打到包中
* jar-with-dependencies : 會將所有依賴都解壓打包到生成物中
* src :只將源碼目錄下的文件打包
* project : 將整個project資源打包
使用 descriptors,指定打包文件 src/assembly/src.xml,在該配置文件內指定打包操作。
~~~
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/src.xml</descriptor>
</descriptors>
</configuration>
[...]
</project>
~~~
要查看它們的詳細定義,可以到maven-assembly-plugin-2.4.jar里去看,例如對應 bin 的assembly descriptor 如下:
~~~
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/site</directory>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
</assembly>
~~~
## 描述符文件元素
~~~
<id>release</id>
~~~
id 標識符,添加到生成文件名稱的后綴符。如果指定 id 的話,目標文件則是 `${artifactId}-${id}.tar.gz`
## formats
maven-assembly-plugin 支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同時指定多個打包格式
~~~
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
~~~
## dependencySets
用來定制工程依賴 jar 包的打包方式,核心元素如下表所示

~~~
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
</dependencySets>
~~~
## fileSets
管理一組文件的存放位置,核心元素如下表所示。

~~~
<fileSets>
<fileSet>
<includes>
<include>bin/**</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<includes>
<include>/conf/**</include>
<include>logs</include>
</includes>
</fileSet>
</fileSets>
~~~
## files
可以指定目的文件名到指定目錄,其他和 fileSets 相同,核心元素如下表所示

~~~
<files>
<file>
<source>README.txt</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
~~~
例子:
pom.xml
~~~
<build>
<finalName>scribe-log4j2-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/release.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
~~~
release.xml
~~~
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<includes>
<include>bin/**</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<includes>
<include>/conf/**</include>
<include>logs</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>README.txt</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
~~~
## 自定義Assembly Descriptor
~~~
<?xml version='1.0' encoding='UTF-8'?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>demo</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
~~~
這個定義很簡單:
* format:指定打包類型
* includeBaseDirectory:指定是否包含打包層目錄(比如finalName是output,當值為true,所有文件被放在output目錄下,否則直接放在包的根目錄下)
* fileSets:指定要包含的文件集,可以定義多個fileSet
* directory:指定要包含的目錄
* outputDirectory:指定當前要包含的目錄的目的地
要使用這個assembly descriptor,需要如下配置:
~~~
<configuration>
<finalName>demo</finalName>
<descriptors>
<descriptor>assemblies/demo.xml</descriptor>
</descriptors>
<outputDirectory>output</outputDirectory>
</configuration>
~~~
最后會生成一個demo-demo.jar 文件在目錄 output 下,其中前一個demo來自finalName,后一個demo來自assembly descriptor中的id,其中的內容和默認的打包出來的jar類似。
如果只想有finalName,則增加配置:
~~~
<appendAssemblyId>false</appendAssemblyId>
~~~
**添加文件**
上面演示了添加所有編譯后的資源,同樣的可以增加其他資源,例如想添加當前工程目錄下的某個文件 b.txt ,在assembly descriptor的assembly結點下增加
~~~
<files>
<file>
<source>b.txt</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
~~~
這里用到了 files 元素類型,可以想象 fileSets 下的結點都是針對文件夾的;files 下的結點都是針對文件的。
也可以改變打包后的文件名,例如上面的 b.txt ,希望打包后的名字為 b.txt.bak, 只需要在file 里添加以下配置 :
~~~
<destName>b.txt.bak</destName>
~~~
**排除文件**
在fileSet里可以使用includes 和 excludes來更精確的控制哪些文件要添加,哪些文件要排除。
例如要排除某個目錄下所有的txt文件:
~~~
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>**/*.txt</exclude>
</excludes>
</fileSet>
~~~
或者某個目錄下只想 .class 文件:
~~~
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*.class</include>
</includes>
</fileSet>
~~~
**添加依賴**
如果想把一些依賴庫打到包里,可以用 dependencySets 元素,例如最簡單的,把當前工程的所有依賴都添加到包里:
~~~
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
</dependencySet>
</dependencySets>
~~~
如果要排除工程自身生成的jar,則可以添加:
~~~
<useProjectArtifact>false</useProjectArtifact>
~~~
unpack參數可以控制依賴包是否在打包進來時是否解開,例如解開所有包,添加以下配置
~~~
<unpack>true</unpack>
~~~
和 fileSet 一樣,可以使用 excludes 和 includes 來更詳細的控制哪些依賴需要打包進來;另外 useProjectAttachments,useTransitiveDependencies,useTransitiveFiltering等參數可以對間接依賴、傳遞依賴進行控制
## 其他選項
* moduleSets:當有子模塊時候用
* repositories:想包含庫的時候用
* containerDescriptorHandlers:可以進行一些合并,定義ArtifactHandler之類的時候可以用
* componentDescriptors:如上所述,可以包含一些componentDescriptor定義,這些定義可以被多個assembly共享
## Assembly Plugin更多配置
**指定Main-Class**
archive的一個重要用處就是配置生成的MANIFEST.MF文件。默認會生成一個MANIFEST.MF文件,不過這個文件默認值沒什么意義。如果想指定生成jar的Main-Class,可以如下配置:
~~~
<archive>
<manifest>
<mainClass>demo.DemoMain</mainClass>
</manifest>
</archive>
~~~
**添加MANIFEST項**
除了可以指定Main-Class外,還可以添加任意項。比如在OSGI bundle的MANIFEST.MF定義里就有很多用來定義bundle的屬性的項,如Import-Package,Export-Package等等。要添加項,可以使用如下配置:
~~~
<archive>
<manifestEntries>
<Import-Package>javax.xml.ws.*</Import-Package>
</manifestEntries>
</archive>
~~~
**指定MANIFEST.MF文件**
還可以直接指定MANIFEST.MF文件。如下:
~~~
<archive>
<manifestFile>META-INF/MANIFEST.MF</manifestFile>
</archive>
~~~
# 例子一
在使用maven來管理項目時,項目除了web項目,還有可能為控制臺程序,一般用于開發一些后臺服務的程序。最近在工作中也遇到了這種場景,使用quartz開發一個任務調度程序。程序中依賴很多jar包,項目的啟動時只需要初始化spring容器即可
使用方法
使用一個簡單的基于spring框架的demo來做程序示例,來介紹maven assembly插件的使用方法。
項目中的代碼目錄如下:

在以上代碼目錄中,assembly目錄下為打包的描述文件,下面會詳細介紹該文件,bin目錄下為啟動腳本以及readme等文件,main下為maven標準中建立的文件,java代碼以及配置文件位于該目錄下。
打包完成后壓縮包目錄如下:

打包完成后,我們可以看到bin目錄來存放啟動腳本等文件,config為配置文件,lib下為運行時依賴的jar包。
使用maven assembly插件需要在pom文件中配置,添加這個插件
~~~
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>make-zip</id>
<!-- 綁定到package生命周期階段上 -->
<phase>package</phase>
<goals>
<!-- 綁定到package生命周期階段上 -->
<goal>single</goal>
</goals>
<configuration>
<descriptors> <!--描述文件路徑-->
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
~~~
其中execution節點,我們配置了執行maven assembly插件的一些配置,descriptor節點配置指向assembly.xml的路徑。
在assembly.xml配置了,我們打包的目錄以及相應的設置
~~~
<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>
<fileSets>
<fileSet>
<directory>${project.basedir}\src\main\resources</directory>
<outputDirectory>\</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\src\bin</directory>
<outputDirectory>\bin</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<!-- 將scope為runtime的依賴包打包到lib目錄下。 -->
<scope>runtime</scope>
</dependencySet>
</dependencySets></assembly>
~~~
assembly.xml的配置項非常多,可以參考http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
以上只是用了很少的一部分。
format設置包輸出的格式,以上格式設置的為zip格式,目前還支持zip,tar,tar.gz,tar.bz2,jar,dir,war格式
fileSet定義代碼目錄中與輸出目錄的映射,在該節點下還有 <includes/>,<excludes/>兩個非常有用的節點。
比如:
~~~
<fileSet>
<directory>${project.basedir}\src\main\resources</directory>
<outputDirectory>\</outputDirectory>
<includes>
<include>some/path</include>
</includes>
<excludes>
<exclude>some/path1</exclude>
</excludes>
</fileSet>
~~~
以上代碼表示歸檔時包括some/path,不包括some/path1
dependencySets節點下為依賴設置
在上述配置中,表示所有運行時依賴的jar包歸檔到lib目錄下。在上述截圖中lib目錄下的文件就是所有依賴的jar包

# 例子二
## 需求
打一個zip包,包含如下:

bin為程序腳本,啟動和停止
lib為依賴包
根目錄下為配置文件和項目jar包
## 插件了解

## 配置
~~~
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<mainClass>com.jd.bt.ZuulApplication</mainClass>
<!-- to create a class path to your dependecies you have to fill true in this field -->
<!-- 增加classpath -->
<addClasspath>true</addClasspath>
<!-- classpath路徑前綴 -->
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>./</Class-Path>
</manifestEntries>
</archive>
<excludes>
<!--注意從編譯結果目錄開始算目錄結構-->
<exclude>/*.yml</exclude>
<exclude>/*.properties</exclude>
<exclude>/*.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- not append assembly id in release file name -->
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/depolyment.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
~~~
**對于maven-jar-plugin配置**
其中manifest的部分是核心,在可執行的jar文件中,打包后會在jar文件內的META-INF文件夾下,生成一個MANIFEST.MF文件,里面記錄了可執行文件的一些相關配置,比如像上面一段代碼中所配置的內容,這里面就配置了可執行jar文件未來讀取classpath的相對目錄位置在什么地方,以及引入的jar文件都有哪些,上面的配置就是classpath目錄是./
mainClass配置表示,哪個class作為程序的入口來執行
addClasspath配置表示,是否將依賴的classpath一起打包
classpathPrefix配置表示,依賴的classpath的前綴,也就是打包后生成的MANIFEST.MF文件里,引入的jar文件都會加上前綴,lib/,比如fastjson-1.2.7.jar,在mainfest文件里就會是lib/fastjson-1.2.7.jar
excludes配置表示,排除哪些文件夾不被打包進去
注意:其實maven-jar-plugin主要就是配置了MANIFEST.MF這個文件而已,就是讓可執行文件知道自己怎么執行,加載哪些文件執行的描述,剩下的工作交由maven-assembly-plugin來處理
最終壓縮的文件格式,為zip,fileSets中配置了需要將那些文件打包到最終壓縮包中,
如配置文件包括了啟動腳本bin文件夾,里面放著shell的啟動腳本,相關的配置文件src/main/resources,里面放著整個程序提取的properties等相關的配置文件
最終可運行的jar文件,使用了${project.build.directory}變量,也就是通過maven-jar-plugin生成的那個jar文件
dependencySets里面配置了依賴庫最終輸出到lib文件夾下,與上面的maven-jar-plugin配置生成的manifest文件路徑相對應,這樣可運行jar就會按照manifest的路徑來找相應的文件進行加載
**src/main/assembly/depolyment.xml配置**
~~~
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/bin</directory>
<outputDirectory>bin/</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
<excludes>
<exclude>${groupId}:${artifactId}</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
~~~
**start.sh和stop.sh**
`start.sh`
~~~
#!/bin/bash
ARTIFACT_ID=jd-bt-microservice-gateway-zuul
VERSION=0.0.1-SNAPSHOT
main_jar=${ARTIFACT_ID}-${VERSION}.jar
PIDS=`ps aux|grep ${main_jar} |grep -v "grep" |awk '{print $2}'`
if [ ! -z "$PIDS" ]; then
echo "${ARTIFACT_ID} already started!"
echo "PID: $PIDS"
exit 0;
fi
BIN_PATH="${JAVA_HOME}/bin"
LOG_PATH="/Users/lihongxu/log/${ARTIFACT_ID}/"
mkdir -p $LOG_PATH
echo "ready start ${main_jar}";
nohup $BIN_PATH/java -server -Xms4096m -Xmx4096m -jar ../${main_jar} >$LOG_PATH/nohup.log 2>&1 &
sleep 5
PIDS=`ps aux|grep ${main_jar} |grep -v "grep" |awk '{print $2}'`
if [ ! -z "$PIDS" ]; then
echo " ${ARTIFACT_ID} Started Successed,pid:${PIDS}"
exit 0;
else
echo " ${ARTIFACT_ID} Started Failed"
exit 1;
fi
~~~
`stop.sh`
~~~
#!/bin/bash
ARTIFACT_ID=jd-bt-microservice-gateway-zuul
VERSION=0.0.1-SNAPSHOT
main_jar=${ARTIFACT_ID}-${VERSION}.jar
PIDS=`ps aux|grep ${main_jar} |grep -v "grep" |awk '{print $2}'`
if [ ! -z "$PIDS" ]; then
kill -9 "$PIDS"
echo " ${ARTIFACT_ID} is stop !"
echo " PID: $PIDS"
exit 0;
fi
~~~
## 啟動
java -cp 和 -classpath 一樣,是指定類運行所依賴其他類的路徑,通常是類庫,jar包之類,需要全路徑到jar包,window上分號";",linux使用":"
* 格式:
`java -cp .;myClass.jar packname.mainclassname`
表達式支持通配符,例如:
`java -cp .;c:\classes01\myClass.jar;c:\classes02\*.jar packname.mainclassname`
* 運行jar
`java -jar myClass.jar`
執行該命令時,會用到目錄META-INF\MANIFEST.MF文件,在該文件中,有一個叫Main-Class的參數,它說明了java -jar命令執行的類。
* 運行jar和cp
用maven導出的包中,如果沒有在pom文件中將依賴包打進去,是沒有依賴包。
1. 打包時指定了主類,可以直接用java -jar xxx.jar。
2. 打包是沒有指定主類,可以用java -cp xxx.jar 主類名稱(絕對路徑)。
3. 要引用其他的jar包,可以用java -classpath $CLASSPATH:xxxx.jar 主類名稱(絕對路徑)。其中 -classpath 指定需要引入的類。
實例
下面基于pom和META-INF\MANIFEST.MF兩個文件的配置,進行了三種情況的測試:
pom.xml的build配置:
~~~
<build>
<!--<finalName>test-1.0-SNAPSHOT</finalName>-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>test.core.Core</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<!--下面是為了使用 mvn package命令,如果不加則使用mvn assembly-->
<executions>
<execution>
<id>make-assemble</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
~~~
META-INF\MANIFEST.MF的內容:
Manifest-Version: 1.0
Main-Class: test.core.Core
1. pom中build指定mainClass 但是 META-INF\MANIFEST.MF文件中沒有指定Main-Class: test.core.Core
~~~
java -jar test-jar-with-dependencies.jar //執行成功
java -cp test-jar-with-dependencies.jar test.core.Core //執行失敗,提示jar中沒有主清單屬性
~~~
2. pom中build沒有指定mainClass 但是 META-INF\MANIFEST.MF文件中指定了Main-Class: test.core.Core
~~~
java -jar test-jar-with-dependencies.jar //執行失敗,提示jar中沒有主清單屬性
java -cp test-jar-with-dependencies.jar test.core.Core //執行成功
~~~
3. pom中build指定mainClass && META-INF\MANIFEST.MF文件中增加了Main-Class: test.core.Core
~~~
java -cp test-jar-with-dependencies.jar test.core.Core //執行成功
java -jar test-jar-with-dependencies.jar //執行成功
~~~
- 基礎
- 編譯和安裝
- classpath到底是什么?
- 編譯運行
- 安裝
- sdkman多版本
- jabba多版本
- java字節碼查看
- 數據類型
- 簡介
- 整形
- char和int
- 變量和常量
- 大數值運算
- 基本類型包裝類
- Math類
- 內存劃分
- 位運算符
- 方法相關
- 方法重載
- 可變參數
- 方法引用
- 面向對象
- 定義
- 繼承和覆蓋
- 接口和抽象類
- 接口定義增強
- 內建函數式接口
- 多態
- 泛型
- final和static
- 內部類
- 包
- 修飾符
- 異常
- 枚舉類
- 代碼塊
- 對象克隆
- BeanUtils
- java基礎類
- scanner類
- Random類
- System類
- Runtime類
- Comparable接口
- Comparator接口
- MessageFormat類
- NumberFormat
- 數組相關
- 數組
- Arrays
- string相關
- String
- StringBuffer
- StringBuilder
- 正則
- 日期類
- Locale類
- Date
- DateFormat
- SimpleDateFormat
- Calendar
- 新時間日期API
- 簡介
- LocalDate,LocalTime,LocalDateTime
- Instant時間點
- 帶時區的日期,時間處理
- 時間間隔
- 日期時間校正器
- TimeUnit
- 用yyyy
- 集合
- 集合和迭代器
- ArrayList集合
- List
- Set
- 判斷集合唯一
- Map和Entry
- stack類
- Collections集合工具類
- Stream數據流
- foreach不能修改內部元素
- of方法
- IO
- File類
- 字節流stream
- 字符流Reader
- IO流分類
- 轉換流
- 緩沖流
- 流的操作規律
- properties
- 序列化流與反序列化流
- 打印流
- System類對IO支持
- commons-IO
- IO流總結
- NIO
- 異步與非阻塞
- IO通信
- Unix的IO模型
- epoll對于文件描述符操作模式
- 用戶空間和內核空間
- NIO與普通IO的主要區別
- Paths,Path,Files
- Buffer
- Channel
- Selector
- Pipe
- Charset
- NIO代碼
- 多線程
- 創建線程
- 線程常用方法
- 線程池相關
- 線程池概念
- ThreadPoolExecutor
- Runnable和Callable
- 常用的幾種線程池
- 線程安全
- 線程同步的幾種方法
- synchronized
- 死鎖
- lock接口
- ThreadLoad
- ReentrantLock
- 讀寫鎖
- 鎖的相關概念
- volatile
- 釋放鎖和不釋放鎖的操作
- 等待喚醒機制
- 線程狀態
- 守護線程和普通線程
- Lamda表達式
- 反射相關
- 類加載器
- 反射
- 注解
- junit注解
- 動態代理
- 網絡編程相關
- 簡介
- UDP
- TCP
- 多線程socket上傳圖片
- NIO
- JDBC相關
- JDBC
- 預處理
- 批處理
- 事務
- properties配置文件
- DBUtils
- DBCP連接池
- C3P0連接池
- 獲得MySQL自動生成的主鍵
- Optional類
- Jigsaw模塊化
- 日志相關
- JDK日志
- log4j
- logback
- xml
- tomcat
- maven
- 簡介
- 倉庫
- 目錄結構
- 常用命令
- 生命周期
- idea配置
- jar包沖突
- 依賴范圍
- 私服
- 插件
- git-commit-id-plugin
- maven-assembly-plugin
- maven-resources-plugin
- maven-compiler-plugin
- versions-maven-plugin
- maven-source-plugin
- tomcat-maven-plugin
- 多環境
- 自定義插件
- stream
- swing
- json
- jackson
- optional
- junit
- gradle
- servlet
- 配置
- ServletContext
- 生命周期
- HttpServlet
- request
- response
- 亂碼
- session和cookie
- cookie
- session
- jsp
- 簡介
- 注釋
- 方法,成員變量
- 指令
- 動作標簽
- 隱式對象
- EL
- JSTL
- javaBean
- listener監聽器
- Filter過濾器
- 圖片驗證碼
- HttpUrlConnection
- 國際化
- 文件上傳
- 文件下載
- spring
- 簡介
- Bean
- 獲取和實例化
- 屬性注入
- 自動裝配
- 繼承和依賴
- 作用域
- 使用外部屬性文件
- spel
- 前后置處理器
- 生命周期
- 掃描規則
- 整合多個配置文件
- 注解
- 簡介
- 注解分層
- 類注入
- 分層和作用域
- 初始化方法和銷毀方法
- 屬性
- 泛型注入
- Configuration配置文件
- aop
- aop的實現
- 動態代理實現
- cglib代理實現
- aop名詞
- 簡介
- aop-xml
- aop-注解
- 代理方式選擇
- jdbc
- 簡介
- JDBCTemplate
- 事務
- 整合
- junit整合
- hibernate
- 簡介
- hibernate.properties
- 實體對象三種狀態
- 檢索方式
- 簡介
- 導航對象圖檢索
- OID檢索
- HQL
- Criteria(QBC)
- Query
- 緩存
- 事務管理
- 關系映射
- 注解
- 優化
- MyBatis
- 簡介
- 入門程序
- Mapper動態代理開發
- 原始Dao開發
- Mapper接口開發
- SqlMapConfig.xml
- map映射文件
- 輸出返回map
- 輸入參數
- pojo包裝類
- 多個輸入參數
- resultMap
- 動態sql
- 關聯
- 一對一
- 一對多
- 多對多
- 整合spring
- CURD
- 占位符和sql拼接以及參數處理
- 緩存
- 延遲加載
- 注解開發
- springMVC
- 簡介
- RequestMapping
- 參數綁定
- 常用注解
- 響應
- 文件上傳
- 異常處理
- 攔截器
- springBoot
- 配置
- 熱更新
- java配置
- springboot配置
- yaml語法
- 運行
- Actuator 監控
- 多環境配置切換
- 日志
- 日志簡介
- logback和access
- 日志文件配置屬性
- 開機自啟
- aop
- 整合
- 整合Redis
- 整合Spring Data JPA
- 基本查詢
- 復雜查詢
- 多數據源的支持
- Repository分析
- JpaSpeci?cationExecutor
- 整合Junit
- 整合mybatis
- 常用注解
- 基本操作
- 通用mapper
- 動態sql
- 關聯映射
- 使用xml
- spring容器
- 整合druid
- 整合郵件
- 整合fastjson
- 整合swagger
- 整合JDBC
- 整合spingboot-cache
- 請求
- restful
- 攔截器
- 常用注解
- 參數校驗
- 自定義filter
- websocket
- 響應
- 異常錯誤處理
- 文件下載
- 常用注解
- 頁面
- Thymeleaf組件
- 基本對象
- 內嵌對象
- 上傳文件
- 單元測試
- 模擬請求測試
- 集成測試
- 源碼解析
- 自動配置原理
- 啟動流程分析
- 源碼相關鏈接
- Servlet,Filter,Listener
- springcloud
- 配置
- 父pom
- 創建子工程
- Eureka
- Hystrix
- Ribbon
- Feign
- Zuul
- kotlin
- 基本數據類型
- 函數
- 區間
- 區塊鏈
- 簡介
- linux
- ulimit修改
- 防止syn攻擊
- centos7部署bbr
- debain9開啟bbr
- mysql
- 隔離性
- sql執行加載順序
- 7種join
- explain
- 索引失效和優化
- 表連接優化
- orderby的filesort問題
- 慢查詢
- show profile
- 全局查詢日志
- 死鎖解決
- sql
- 主從
- IDEA
- mac快捷鍵
- 美化界面
- 斷點調試
- 重構
- springboot-devtools熱部署
- IDEA進行JAR打包
- 導入jar包
- ProjectStructure
- toString添加json模板
- 配置maven
- Lombok插件
- rest client
- 文檔顯示
- sftp文件同步
- 書簽
- 代碼查看和搜索
- postfix
- live template
- git
- 文件頭注釋
- JRebel
- 離線模式
- xRebel
- github
- 連接mysql
- 選項沒有Java class的解決方法
- 擴展
- 項目配置和web部署
- 前端開發
- json和Inject language
- idea內存和cpu變高
- 相關設置
- 設計模式
- 單例模式
- 簡介
- 責任鏈
- JUC
- 原子類
- 原子類簡介
- 基本類型原子類
- 數組類型原子類
- 引用類型原子類
- JVM
- JVM規范內存解析
- 對象的創建和結構
- 垃圾回收
- 內存分配策略
- 備注
- 虛擬機工具
- 內存模型
- 同步八種操作
- 內存區域大小參數設置
- happens-before
- web service
- tomcat
- HTTPS
- nginx
- 變量
- 運算符
- 模塊
- Rewrite規則
- Netty
- netty為什么沒用AIO
- 基本組件
- 源碼解讀
- 簡單的socket例子
- 準備netty
- netty服務端啟動
- 案例一:發送字符串
- 案例二:發送對象
- websocket
- ActiveMQ
- JMS
- 安裝
- 生產者-消費者代碼
- 整合springboot
- kafka
- 簡介
- 安裝
- 圖形化界面
- 生產過程分析
- 保存消息分析
- 消費過程分析
- 命令行
- 生產者
- 消費者
- 攔截器interceptor
- partition
- kafka為什么快
- kafka streams
- kafka與flume整合
- RabbitMQ
- AMQP
- 整體架構
- RabbitMQ安裝
- rpm方式安裝
- 命令行和管控頁面
- 消息生產與消費
- 整合springboot
- 依賴和配置
- 簡單測試
- 多方測試
- 對象支持
- Topic Exchange模式
- Fanout Exchange訂閱
- 消息確認
- java client
- RabbitAdmin和RabbitTemplate
- 兩者簡介
- RabbitmqAdmin
- RabbitTemplate
- SimpleMessageListenerContainer
- MessageListenerAdapter
- MessageConverter
- 詳解
- Jackson2JsonMessageConverter
- ContentTypeDelegatingMessageConverter
- lucene
- 簡介
- 入門程序
- luke查看索引
- 分析器
- 索引庫維護
- elasticsearch
- 配置
- 插件
- head插件
- ik分詞插件
- 常用術語
- Mapping映射
- 數據類型
- 屬性方法
- Dynamic Mapping
- Index Template 索引模板
- 管理映射
- 建立映射
- 索引操作
- 單模式下CURD
- mget多個文檔
- 批量操作
- 版本控制
- 基本查詢
- Filter過濾
- 組合查詢
- 分析器
- redis
- String
- list
- hash
- set
- sortedset
- 發布訂閱
- 事務
- 連接池
- 管道
- 分布式可重入鎖
- 配置文件翻譯
- 持久化
- RDB
- AOF
- 總結
- Lettuce
- zookeeper
- zookeeper簡介
- 集群部署
- Observer模式
- 核心工作機制
- zk命令行操作
- zk客戶端API
- 感知服務動態上下線
- 分布式共享鎖
- 原理
- zab協議
- 兩階段提交協議
- 三階段提交協議
- Paxos協議
- ZAB協議
- hadoop
- 簡介
- hadoop安裝
- 集群安裝
- 單機安裝
- linux編譯hadoop
- 添加新節點
- 退役舊節點
- 集群間數據拷貝
- 歸檔
- 快照管理
- 回收站
- 檢查hdfs健康狀態
- 安全模式
- hdfs簡介
- hdfs命令行操作
- 常見問題匯總
- hdfs客戶端操作
- mapreduce工作機制
- 案例-單詞統計
- 局部聚合Combiner
- combiner流程
- combiner案例
- 自定義排序
- 自定義Bean對象
- 排序的分類
- 案例-按總量排序需求
- 一次性完成統計和排序
- 分區
- 分區簡介
- 案例-結果分區
- 多表合并
- reducer端合并
- map端合并(分布式緩存)
- 分組
- groupingComparator
- 案例-求topN
- 全局計數器
- 合并小文件
- 小文件的弊端
- CombineTextInputFormat機制
- 自定義InputFormat
- 自定義outputFormat
- 多job串聯
- 倒排索引
- 共同好友
- 串聯
- 數據壓縮
- InputFormat接口實現類
- yarn簡介
- 推測執行算法
- 本地提交到yarn
- 框架運算全流程
- 數據傾斜問題
- mapreduce的優化方案
- HA機制
- 優化
- Hive
- 安裝
- shell參數
- 數據類型
- 集合類型
- 數據庫
- DDL操作
- 創建表
- 修改表
- 分區表
- 分桶表
- DML操作
- load
- insert
- select
- export,import
- Truncate
- 注意
- 嚴格模式
- 函數
- 內置運算符
- 內置函數
- 自定義函數
- Transfrom實現
- having和where不同
- 壓縮
- 存儲
- 存儲和壓縮結合使用
- explain詳解
- 調優
- Fetch抓取
- 本地模式
- 表的優化
- GroupBy
- count(Distinct)去重統計
- 行列過濾
- 動態分區調整
- 數據傾斜
- 并行執行
- JVM重用
- 推測執行
- reduce內存和個數
- sql查詢結果作為變量(shell)
- youtube
- flume
- 簡介
- 安裝
- 常用組件
- 攔截器
- 案例
- 監聽端口到控制臺
- 采集目錄到HDFS
- 采集文件到HDFS
- 多個agent串聯
- 日志采集和匯總
- 單flume多channel,sink
- 自定義攔截器
- 高可用配置
- 使用注意
- 監控Ganglia
- sqoop
- 安裝
- 常用命令
- 數據導入
- 準備數據
- 導入數據到HDFS
- 導入關系表到HIVE
- 導入表數據子集
- 增量導入
- 數據導出
- 打包腳本
- 作業
- 原理
- azkaban
- 簡介
- 安裝
- 案例
- 簡介
- command類型單一job
- command類型多job工作流flow
- HDFS操作任務
- mapreduce任務
- hive腳本任務
- oozie
- 安裝
- hbase
- 簡介
- 系統架構
- 物理存儲
- 尋址機制
- 讀寫過程
- 安裝
- 命令行
- 基本CURD
- java api
- CURD
- CAS
- 過濾器查詢
- 建表高級屬性
- 與mapreduce結合
- 與sqoop結合
- 協處理器
- 參數配置優化
- 數據備份和恢復
- 節點管理
- 案例-點擊流
- 簡介
- HUE
- 安裝
- storm
- 簡介
- 安裝
- 集群啟動及任務過程分析
- 單詞統計
- 單詞統計(接入kafka)
- 并行度和分組
- 啟動流程分析
- ACK容錯機制
- ACK簡介
- BaseRichBolt簡單使用
- BaseBasicBolt簡單使用
- Ack工作機制
- 本地目錄樹
- zookeeper目錄樹
- 通信機制
- 案例
- 日志告警
- 工具
- YAPI
- chrome無法手動拖動安裝插件
- 時間和空間復雜度
- jenkins
- 定位cpu 100%
- 常用腳本工具
- OOM問題定位
- scala
- 編譯
- 基本語法
- 函數
- 數組常用方法
- 集合
- 并行集合
- 類
- 模式匹配
- 異常
- tuple元祖
- actor并發編程
- 柯里化
- 隱式轉換
- 泛型
- 迭代器
- 流stream
- 視圖view
- 控制抽象
- 注解
- spark
- 企業架構
- 安裝
- api開發
- mycat
- Groovy
- 基礎