1. 程式人生 > >Maven scala和java 混合打包

Maven scala和java 混合打包

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