在maven项目中构建scala模块,这样的话可以java和scala互相调用,最好在环境变量中配置scala home,ide加载相关的模块进行编译运行。
pom中的配置如下:
1<dependencies> 2 <dependency> 3 <groupId>org.scala-lang</groupId> 4 <artifactId>scala-library</artifactId> 5 <version>2.10.4</version> 6 </dependency> 7 <dependency> 8 <groupId>org.scala-lang</groupId> 9 <artifactId>scala-actors</artifactId> 10 <version>2.10.4</version> 11 </dependency> 12 <dependency> 13 <groupId>junit</groupId> 14 <artifactId>junit</artifactId> 15 <version>4.8.1</version> 16 <scope>test</scope> 17 </dependency> 18 <dependency> 19 <groupId>org.slf4j</groupId> 20 <artifactId>slf4j-api</artifactId> 21 <version>1.5.11</version> 22 <scope>provided</scope> 23 </dependency> 24 <dependency> 25 <groupId>com.google.guava</groupId> 26 <artifactId>guava</artifactId> 27 <version>15.0</version> 28 <scope>provided</scope> 29 </dependency> 30 31 <dependency> 32 <groupId>org.slf4j</groupId> 33 <artifactId>jcl-over-slf4j</artifactId> 34 <version>1.5.11</version> 35 <scope>test</scope> 36 </dependency> 37 <dependency> 38 <groupId>commons-logging</groupId> 39 <artifactId>commons-logging</artifactId> 40 <version>99.0-does-not-exist</version> 41 <scope>test</scope> 42 </dependency> 43 <dependency> 44 <groupId>org.slf4j</groupId> 45 <artifactId>slf4j-log4j12</artifactId> 46 <version>1.5.11</version> 47 <scope>test</scope> 48 </dependency> 49 <dependency> 50 <groupId>log4j</groupId> 51 <artifactId>log4j</artifactId> 52 <version>1.2.15</version> 53 <scope>test</scope> 54 <exclusions> 55 <exclusion> 56 <groupId>javax.mail</groupId> 57 <artifactId>mail</artifactId> 58 </exclusion> 59 <exclusion> 60 <groupId>javax.jms</groupId> 61 <artifactId>jms</artifactId> 62 </exclusion> 63 </exclusions> 64 </dependency> 65 </dependencies> 66 67 <build> 68 <plugins> 69 <plugin> 70 <groupId>org.apache.maven.plugins</groupId> 71 <artifactId>maven-compiler-plugin</artifactId> 72 <version>2.3.2</version> 73 <configuration> 74 <source>1.6</source> 75 <target>1.6</target> 76 <encoding>UTF-8</encoding> 77 </configuration> 78 </plugin> 79 <plugin> 80 <groupId>org.apache.maven.plugins</groupId> 81 <artifactId>maven-resources-plugin</artifactId> 82 <version>2.4.3</version> 83 <configuration> 84 <encoding>UTF-8</encoding> 85 <useDefaultDelimiters>false</useDefaultDelimiters> 86 <delimiters> 87 <delimiter>${*}</delimiter> 88 </delimiters> 89 </configuration> 90 </plugin> 91 <plugin> 92 <groupId>net.alchim31.maven</groupId> 93 <artifactId>scala-maven-plugin</artifactId> 94 <version>3.1.6</version> 95 <configuration> 96 <sourceDir>src/main/scala</sourceDir> 97 <testSourceDir>src/test/scala</testSourceDir> 98 <encoding>UTF-8</encoding> 99 <args> 100 <arg>-encoding</arg> 101 <arg>UTF-8</arg> 102 </args> 103 </configuration> 104 105 <executions> 106 <execution> 107 <id>scala-compile-first</id> 108 <phase>process-resources</phase> 109 <goals> 110 <goal>add-source</goal> 111 <goal>compile</goal> 112 </goals> 113 </execution> 114 <execution> 115 <id>scala-test-compile</id> 116 <phase>process-test-resources</phase> 117 <goals> 118 <goal>testCompile</goal> 119 </goals> 120 </execution> 121 <execution> 122 <id>scala-doc-generator</id> 123 <phase>package</phase> 124 <goals> 125 <goal>doc-jar</goal> 126 </goals> 127 </execution> 128 </executions> 129 </plugin> 130 </plugins> 131 </build>