idea用maven構建java+scala專案
阿新 • • 發佈:2019-01-09
1. 新建專案
File->new project
選擇maven專案,勾上Create from archetype,選擇
scala-archetype-simple
標記路徑為Source root:在目錄上右鍵 -> “Mark directory as”
兩個Source root
- src/main/java
- src/main/scala
兩個test source root
- src/test/java
- src/test/scala
2. pom配置
<properties>
<project.build.sourceEncoding >UTF-8</project.build.sourceEncoding>
<hadoop.version>2.7.3</hadoop.version>
<compile.version>1.8</compile.version>
<junit.version>4.12</junit.version>
</properties>
<build>
<plugins>
<plugin >
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>compile-scala</id >
<phase>compile</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile-scala</id>
<phase>test-compile</phase>
<goals>
<goal>add-source</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${compile.version}</source>
<target>${compile.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
3. 打包命令
mvn clean scala:compile compile package
4. 檢視jar包內容
jar vtf xxx.jar
大家有興趣的可以關注我的公眾號,涉及分散式系統、大資料和個人成長分享,歡迎大家一起交流進步