1.删除pom文件中的sourceDirectory 和 testSourceDirectory 两个标签
如果scala和java源码在同一个源目录下可以忽略,即不删除
2.添加打包插件
1)java打包插件:
<!-- 这是个编译java代码的 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>6</source>
<target>6</target>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
2)scala打包插件:
<!-- 这是个编译scala代码的 -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
3)将依赖也进行打包
<!--maven-assembly-plugin不能打包spring Framework框架的项目,可以使用maven-shade-plugin插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>com.xxg.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
4)自定义包名:
<!--在build的标签内输入finalName标签,标签的内容就是自定义的包名-->
<finalName>ROOT</finalName>
5)打包命令:
mvn clean package -DskipTests
6)参考文献:
https://blog.csdn.net/daiyutage/article/details/53739452
https://www.cnblogs.com/rightmin/p/6207665.html