idea用maven构建java+scala项目

来源:互联网 发布:java注册登录代码 编辑:程序博客网 时间:2024/06/05 15:51

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

原创粉丝点击