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

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值