Maven scala和java 混合打包

1.删除pom文件中的sourceDirectory 和 testSourceDirectory 两个标签
 如果scala和java源码在同一个源目录下可以忽略,即不删除
2.添加打包插件
1)java打包插件:


<plugin>
    <groupId>org.apache.maven.pluginsgroupId>
    <artifactId>maven-compiler-pluginartifactId>
    <version>3.0version>
    <configuration>
        <source>6source>
        <target>6target>
        <encoding>UTF-8encoding>
    configuration>
    <executions>
        <execution>
            <phase>compilephase>
            <goals>
                <goal>compilegoal>
            goals>
        execution>
    executions>
plugin>

2)scala打包插件:


<plugin>
    <groupId>net.alchim31.mavengroupId>
    <artifactId>scala-maven-pluginartifactId>
    <version>3.2.1version>
    <executions>
        <execution>
            <id>scala-compile-firstid>
            <phase>process-resourcesphase>
            <goals>
                <goal>add-sourcegoal>
                <goal>compilegoal>
            goals>
        execution>
    executions>
plugin>

3)将依赖也进行打包


<plugin>  
    <groupId>org.apache.maven.pluginsgroupId>  
    <artifactId>maven-assembly-pluginartifactId>  
    <version>2.5.5version>  
    <configuration>  
        <archive>  
            <manifest>  
                <mainClass>com.xxg.MainmainClass>  
            manifest>  
        archive>  
        <descriptorRefs>  
            <descriptorRef>jar-with-dependenciesdescriptorRef>  
        descriptorRefs>  
    configuration>  
    <executions>  
        <execution>  
            <id>make-assemblyid>  
            <phase>packagephase>  
            <goals>  
                <goal>singlegoal>  
            goals>  
        execution>  
    executions>  
plugin>

4)自定义包名:


<finalName>ROOTfinalName>

5)打包命令:

mvn clean package -DskipTests

6)参考文献:
https://blog.csdn.net/daiyutage/article/details/53739452
https://www.cnblogs.com/rightmin/p/6207665.html

你可能感兴趣的:(Maven)