下面Maven的pom文件
-
<properties>
-
<maven.compiler.source>1.8
</maven.compiler.source>
-
<maven.compiler.target>1.8
</maven.compiler.target>
-
<encoding>UTF-8
</encoding>
-
<scala.version>2.11.8
</scala.version>
-
<scala.compat.version>2.11
</scala.compat.version>
-
</properties>
-
-
<dependencies>
-
-
<dependency>
-
<groupId>org.scala-lang
</groupId>
-
<artifactId>scala-library
</artifactId>
-
<version>${scala.version}
</version>
-
</dependency>
-
</dependencies>
-
-
<build>
-
<!--scala待编译的文件目录-->
-
<sourceDirectory>src/main/scala
</sourceDirectory>
-
<testSourceDirectory>src/test/scala
</testSourceDirectory>
-
<!--scala插件-->
-
<plugins>
-
<plugin>
-
<groupId>net.alchim31.maven
</groupId>
-
<artifactId>scala-maven-plugin
</artifactId>
-
<version>3.2.2
</version>
-
<executions>
-
<execution>
-
<goals>
-
<goal>compile
</goal>
-
<goal>testCompile
</goal>
-
</goals>
-
<configuration>
-
<args>
-
<!--<arg>-make:transitive</arg>-->
<!--scala2.11 netbean不支持这个参数-->
-
<arg>-dependencyfile
</arg>
-
<arg>${project.build.directory}/.scala_dependencies
</arg>
-
</args>
-
</configuration>
-
</execution>
-
</executions>
-
</plugin>
-
-
<!--manven打包插件-->
-
<plugin>
-
<groupId>org.apache.maven.plugins
</groupId>
-
<artifactId>maven-shade-plugin
</artifactId>
-
<version>2.4.3
</version>
-
<executions>
-
<execution>
-
<phase>package
</phase>
-
<goals>
-
<goal>shade
</goal>
-
</goals>
-
<configuration>
-
<filters>
-
<filter>
-
<artifact>*:*
</artifact>
-
<excludes>
-
<exclude>META-INF/*.SF
</exclude>
-
<exclude>META-INF/*.DSA
</exclude>
-
<exclude>META-INF/*.RSA
</exclude>
-
</excludes>
-
</filter>
-
</filters>
-
<transformers>
-
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
-
<resource>reference.conf
</resource>
-
</transformer>
-
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-
<mainClass>cn.itcast.rpc.Master
</mainClass>
<!--main方法-->
-
</transformer>
-
</transformers>
-
</configuration>
-
</execution>
-
</executions>
-
</plugin>
-
</plugins>
-
</build>
上面是使用Scala2.11的版本,注意scala2.11 netbean不支持这个参数-make:transitive这个参数,所以必须得注释掉
下面是简单的测试:
使用Maven进行jar依赖打包,之前使用Idea的artifacts进行打包,但是导出的jar有可能因为缺少某些信息而无法直接运行,但是使用maven自动的pakage便没有这个问题,而且jar包的大小明显小于artifacts的jar包大小,下面是使用方法
下载完相关的依赖后,会在target的目录下生成下项目的jar包