eclipse 中java/scala 混合的maven项目 工作环境篇

 

  写在前面:基本上靠java吃饭的吧,近两年也有用到scala;但也没有留下什么痕迹,想起每次被问倒在基础知识,那刻对方→_→ 怀疑的眼神~~。so right here, right now ! 从此沉淀下来。然后积沙成堆,积水成河 养成良好的习惯并持之以恒。p( ^ O ^ )q 加油!

 

  一、IDE:scala-IDE(一直用这个),IntelliJ IDEA(耳闻),Netbeans(才知道)

  二、安装m2eclipse-scala插件,URL:http://alchim31.free.fr/m2e-scala/update-site/

  三、创建项目的时候需要搜索、选择插件,要增加URL:http://repo1.maven.org/maven2/archetype-catalog.xml

  四、出现过mvn连不上公共库的问题;

    解决方法:eclipse.ini add : -vmargs -Djava.net.preferIPv4Stack=true

    参考https://www.eclipse.org/forums/index.php/t/270718/(Starting Eclipse with -vmargs -Djava.net.preferIPv4Stack=true works for me)

  五、创建支持scala的mvn项目步骤

    Select New -> Project -> Other and then select Maven Project. On the next window, search forscala-archetype. Make sure you select the one in group net.alchim31.maven, and click Next。

    参考http://scala-ide.org/docs/tutorials/m2eclipse/index.html#create-a-new-scala-maven-project

  六、scala/java 项目mvn打包

    参考http://davidb.github.io/scala-maven-plugin/example_java.html

 1 <dependencies>
 2     ...
 3     <dependency>
 4       <groupId>org.scala-lang</groupId>
 5       <artifactId>scala-library</artifactId>
 6       <version>${scala.version}</version>
 7     </dependency>
 8     ...
 9 </dependencies>
10 
11 <build>
12     <sourceDirectory>src/main</sourceDirectory>
13     <testSourceDirectory>src/test</testSourceDirectory>
14     
15     <pluginManagement>
16         <plugins>
17             <plugin>
18                 <groupId>net.alchim31.maven</groupId>
19                 <artifactId>scala-maven-plugin</artifactId>
20                 <version>3.2.1</version>
21             </plugin>
22             <plugin>
23                 <groupId>org.apache.maven.plugins</groupId>
24                 <artifactId>maven-compiler-plugin</artifactId>
25                 <version>3.2</version>
26             </plugin>
27         </plugins>
28     </pluginManagement>
29         
30     <plugins>
31     
32             <plugin>
33                 <groupId>net.alchim31.maven</groupId>
34                 <artifactId>scala-maven-plugin</artifactId>
35                 <executions>
36                     <execution>
37                         <id>scala-compile-first</id>
38                         <phase>process-resources</phase>
39                         <goals>
40                             <goal>add-source</goal>
41                             <goal>compile</goal>
42                         </goals>
43                     </execution>
44                     <execution>
45                         <id>scala-test-compile</id>
46                         <phase>process-test-resources</phase>
47                         <goals>
48                             <goal>testCompile</goal>
49                         </goals>
50                     </execution>
51                 </executions>
52             </plugin>
53             <plugin>
54                 <groupId>org.apache.maven.plugins</groupId>
55                 <artifactId>maven-compiler-plugin</artifactId>
56                 <executions>
57                     <execution>
58                         <phase>compile</phase>
59                         <goals>
60                             <goal>compile</goal>
61                         </goals>
62                     </execution>
63                 </executions>
64             </plugin>
65     </plugins>
66   </build>
View Code

 

posted @ 2017-02-23 16:34  tjuhenryli  阅读(3492)  评论(1编辑  收藏  举报