第一种 idea自身打包插件
这种方式输出目录在out目录下
第一步
如图所示 依次选择file-projecct structure-artifacts
选择 Artifacts 然后点击+ 选择jar 选择 from module with dependencies
第二步 红框部分可以选择依赖jar包要不要选择 如果不要第三方点击-全部移除即可
可以导出包时不导出第三方jar
第三步
点击 Build–>Build Artifacts–>选择bulid即可
通过maven插件打包
这种方式jar包在target目录下
打包方式和上面不太一样 点击图示左下角 然后点击maven project 选择maven生命周期
选择package可以打包
第一种
可执行jar与依赖分开,依赖在lib目录里
1 <plugin>
2 <groupId>org.apache.maven.plugins</groupId>
3 <artifactId>maven-jar-plugin</artifactId>
4 <version>2.6</version>
5 <configuration>
6 <archive>
7 <manifest>
8 <addClasspath>true</addClasspath>
9 <classpathPrefix>lib/</classpathPrefix>
10 <mainClass>com.xxx.xxxService</mainClass>
11 </manifest>
12 </archive>
13 </configuration>
14 </plugin>
15 <plugin>
16 <groupId>org.apache.maven.plugins</groupId>
17 <artifactId>maven-dependency-plugin</artifactId>
18 <version>2.10</version>
19 <executions>
20 <execution>
21 <id>copy-dependencies</id>
22 <phase>package</phase>
23 <goals>
24 <goal>copy-dependencies</goal>
25 </goals>
26 <configuration>
27 <outputDirectory>${project.build.directory}/lib</outputDirectory>
28 </configuration>
29 </execution>
30 </executions>
31 </plugin>
第二种
把所有依赖打进同一个jar包里
1 <plugin>
2 <artifactId>maven-assembly-plugin</artifactId>
3 <configuration>
4 <descriptorRefs>
5 <descriptorRef>jar-with-dependencies</descriptorRef>
6 </descriptorRefs>
7 <archive>
8 <manifest>
9 <mainClass>com.xxx.xxxService</mainClass>
10 </manifest>
11 </archive>
12 </configuration>
13 <executions>
14 <execution>
15 <id>make-assembly</id>
16 <phase>package</phase>
17 <goals>
18 <goal>single</goal>
19 </goals>
20 </execution>
21 </executions>
22 </plugin>
第三种
也是所有依赖打到一个jar包
transform部分自定义
1 <plugin>
2 <groupId>org.apache.maven.plugins</groupId>
3 <artifactId>maven-shade-plugin</artifactId>
4 <version>2.4.3</version>
5 <executions>
6 <execution>
7 <phase>package</phase>
8 <goals>
9 <goal>shade</goal>
10 </goals>
11 <configuration>
12 <filters>
13 <filter>
14 <artifact>*:*</artifact>
15 <excludes>
16 <exclude>META-INF/*.SF</exclude>
17 <exclude>META-INF/*.DSA</exclude>
18 <exclude>META-INF/*.RSA</exclude>
19 </excludes>
20 </filter>
21 </filters>
22 <transformers>
23 <transformer
24 implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
25 <resource>META-INF/spring.handlers</resource>
26 </transformer>
27 <transformer
28 implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
29 <resource>META-INF/spring.schemas</resource>
30 </transformer>
31 <transformer
32 implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
33 <resource>META-INF/spring.tooling</resource>
34 </transformer>
35 <transformer
36 implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
37 <mainClass>com.xxx.xxxInvoke</mainClass>
38 </transformer>
39 </transformers>
40 <minimizeJar>true</minimizeJar>
41 <shadedArtifactAttached>true</shadedArtifactAttached>
42 </configuration>
43 </execution>
44 </executions>
45 </plugin>
Scala 插件
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
</args>
</configuration>
</plugin>