IDEA Java/Scala混合项目Maven打包
IDEA Java/Scala混合项目Maven打包
1.在建立Maven项目时,选择骨架为maven-archetype-quickstart
2.pom文件内容为:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>scalalearn</groupId> <artifactId>scalalearn</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>scalalearn</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.11.6</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <version>2.15.2</version> <executions> <execution> <id>scala-compile-first</id> <goals> <goal>compile</goal> </goals> <configuration> <includes> <include>**/*.scala</include> </includes> </configuration> </execution> <execution> <id>scala-test-compile</id> <goals> <goal>testCompile</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
3.在src/main下新建scala文件夹,用于存放scala源码,并在project structure中将其设为source目录;在src/main下建立resources/META-INF目录,并建立MANIFEST.MF文件,在里面填入mainclass,并将resources目录设置为资源目录
Main-Class: com.scalalearn.java.main.App
4.设置之好的项目结构如图所示:
5.com.scalalearn.scala.main.ScalaPrint.scala的内容为:
package com.scalalearn.scala.main /** * Created by Administrator on 2016/5/14. */ object ScalaPrint { def print():Unit={ println("I love scala"); } }
com.scalalearn.java.main.App.java的内容为:
package com.scalalearn.java.main; import com.scalalearn.scala.main.ScalaPrint; /** * Hello world! * */ public class App { public static void main( String[] args ) { ScalaPrint.print(); } }
6.打jar包的mvn命令为:mvn clean scala:compile compile package
7.最后会在target目录下生成两个jar包,分别为:scalalearn-1.0-SNAPSHOT.jar和scalalearn-1.0-SNAPSHOT-jar-with-dependencies.jar
8.运行jar效果如下:
相关推荐
Kafka 2020-09-18
Wepe0 2020-10-30
杜倩 2020-10-29
windle 2020-10-29
minerd 2020-10-28
mengzuchao 2020-10-22
Junzizhiai 2020-10-10
bxqybxqy 2020-09-30
风之沙城 2020-09-24
kingszelda 2020-09-22
大唐帝国前营 2020-08-18
yixu0 2020-08-17
TangCuYu 2020-08-15
xiaoboliu00 2020-08-15
songshijiazuaa 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
newfarhui 2020-08-03
likesyour 2020-08-01