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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM