Scala和Java混合项目搭建:(Eclipse)
项目结构:
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0modelVersion> <groupId>com.citi.skygroupId> <artifactId>AkkaPJartifactId> <version>0.0.1-SNAPSHOTversion> <packaging>jarpackaging> <name>AkkaPJname> <url>http://maven.apache.orgurl> <properties> <project.build.sourceEncoding>UTF-8project.build.sourceEncoding> <jdk.version>1.8jdk.version> <scala.version>2.11.8scala.version> <akka.version>2.5.9akka.version> <scalatest.version>3.0.4scalatest.version> properties> <dependencies> <dependency> <groupId>junitgroupId> <artifactId>junitartifactId> <version>4.12version> <scope>testscope> dependency> <dependency> <groupId>org.scala-langgroupId> <artifactId>scala-libraryartifactId> <version>${scala.version}version> dependency> <dependency> <groupId>org.scala-langgroupId> <artifactId>scala-compilerartifactId> <version>${scala.version}version> dependency> <dependency> <groupId>org.scala-langgroupId> <artifactId>scala-reflectartifactId> <version>${scala.version}version> dependency> <dependency> <groupId>com.typesafe.akkagroupId> <artifactId>akka-actor_2.11artifactId> <version>${akka.version}version> dependency> <dependency> <groupId>com.typesafe.akkagroupId> <artifactId>akka-testkit_2.11artifactId> <version>${akka.version}version> <scope>testscope> dependency> <dependency> <groupId>org.scalatestgroupId> <artifactId>scalatest_2.11artifactId> <version>${scalatest.version}version> <scope>testscope> dependency> dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojogroupId> <artifactId>build-helper-maven-pluginartifactId> <version>3.0.0version> <executions> <execution> <id>add-sourceid> <phase>generate-sourcesphase> <goals> <goal>add-sourcegoal> goals> <configuration> <sources> <source>${basedir}/src/main/javasource> <source>${basedir}/src/main/scalasource> sources> configuration> execution> <execution> <id>add-test-sourceid> <phase>generate-sourcesphase> <goals> <goal>add-test-sourcegoal> goals> <configuration> <sources> <source>${basedir}/src/test/javasource> <source>${basedir}/src/test/scalasource> sources> configuration> execution> <execution> <id>add-resourceid> <phase>generate-sourcesphase> <goals> <goal>add-resourcegoal> goals> <configuration> <resources> <resource> <directory>${basedir}/src/main/resourcesdirectory> <filtering>truefiltering> <excludes> <exclude>**/*.javaexclude> excludes> resource> resources> configuration> execution> <execution> <id>add-test-resourceid> <phase>generate-sourcesphase> <goals> <goal>add-test-resourcegoal> goals> <configuration> <resources> <resource> <directory>${basedir}/src/test/resourcesdirectory> <filtering>truefiltering> <excludes> <exclude>**/*.javaexclude> excludes> resource> resources> configuration> execution> executions> plugin> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-compiler-pluginartifactId> <version>3.1version> <configuration> <source>${jdk.version}source> <target>${jdk.version}target> <encoding>${project.build.sourceEncoding}encoding> configuration> plugin> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-shade-pluginartifactId> <version>3.0.0version> <configuration> <createDependencyReducedPom>falsecreateDependencyReducedPom> configuration> <executions> <execution> <phase>packagephase> <goals> <goal>shadegoal> goals> <configuration> <shadedArtifactAttached>trueshadedArtifactAttached> <shadedClassifierName>allInOneshadedClassifierName> <artifactSet> <includes> <include>*:*include> includes> artifactSet> <filters> <filter> <artifact>*:*artifact> <excludes> <exclude>META-INF/*.SFexclude> <exclude>META-INF/*.DSAexclude> <exclude>META-INF/*.RSAexclude> excludes> filter> filters> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.citi.dw.client.ClientTestmainClass> transformer> transformers> configuration> execution> executions> plugin> <plugin> <groupId>net.alchim31.mavengroupId> <artifactId>scala-maven-pluginartifactId> <version>3.3.1version> <executions> <execution> <id>compile-scalaid> <phase>compilephase> <goals> <goal>add-sourcegoal> <goal>compilegoal> goals> execution> <execution> <id>test-compile-scalaid> <phase>test-compilephase> <goals> <goal>add-sourcegoal> <goal>testCompilegoal> goals> execution> executions> <configuration> <scalaVersion>${scala.version}scalaVersion> configuration> plugin> plugins> build> project>
.classpath:
xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" output="target/classes" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> attributes> classpathentry> <classpathentry kind="src" path="src/main/scala"/> <classpathentry kind="src" path="src/main/resources"/> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> attributes> classpathentry> <classpathentry kind="src" path="src/test/scala"/> <classpathentry kind="src" path="src/test/resources"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_121"> <attributes> <attribute name="maven.pomderived" value="true"/> attributes> classpathentry> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> attributes> classpathentry> <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/> <classpathentry kind="output" path="target/classes"/> classpath>
Log:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AkkaPJ 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ AkkaPJ ---
[INFO] Deleting E:\git\AkkaPJ\target
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-source (add-source) @ AkkaPJ ---
[INFO] Source directory: E:\git\AkkaPJ\src\main\java added.
[INFO] Source directory: E:\git\AkkaPJ\src\main\scala added.
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-test-source (add-test-source) @ AkkaPJ ---
[INFO] Test Source directory: E:\git\AkkaPJ\src\test\java added.
[INFO] Test Source directory: E:\git\AkkaPJ\src\test\scala added.
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-resource (add-resource) @ AkkaPJ ---
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-test-resource (add-test-resource) @ AkkaPJ ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ AkkaPJ ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ AkkaPJ ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to E:\git\AkkaPJ\target\classes
[INFO]
[INFO] --- scala-maven-plugin:3.3.1:add-source (compile-scala) @ AkkaPJ ---
[INFO]
[INFO] --- scala-maven-plugin:3.3.1:compile (compile-scala) @ AkkaPJ ---
[WARNING] Expected all dependencies to require Scala version: 2.11.8
[WARNING] com.citi.sky:AkkaPJ:0.0.1-SNAPSHOT requires scala version: 2.11.8
[WARNING] com.citi.sky:AkkaPJ:0.0.1-SNAPSHOT requires scala version: 2.11.8
[WARNING] org.scala-lang:scala-compiler:2.11.8 requires scala version: 2.11.8
[WARNING] org.scala-lang.modules:scala-xml_2.11:1.0.4 requires scala version: 2.11.4
[WARNING] Multiple versions of scala libraries detected!
[INFO] E:\git\AkkaPJ\src\main\java:-1: info: compiling
[INFO] E:\git\AkkaPJ\src\main\scala:-1: info: compiling
[INFO] Compiling 5 source files to E:\git\AkkaPJ\target\classes at 1517634353428
[INFO] prepare-compile in 0 s
[INFO] compile in 2 s
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ AkkaPJ ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ AkkaPJ ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to E:\git\AkkaPJ\target\test-classes
[INFO]
[INFO] --- scala-maven-plugin:3.3.1:add-source (test-compile-scala) @ AkkaPJ ---
[INFO]
[INFO] --- scala-maven-plugin:3.3.1:testCompile (test-compile-scala) @ AkkaPJ ---
[WARNING] Expected all dependencies to require Scala version: 2.11.8
[WARNING] com.citi.sky:AkkaPJ:0.0.1-SNAPSHOT requires scala version: 2.11.8
[WARNING] com.citi.sky:AkkaPJ:0.0.1-SNAPSHOT requires scala version: 2.11.8
[WARNING] org.scala-lang:scala-compiler:2.11.8 requires scala version: 2.11.8
[WARNING] org.scala-lang.modules:scala-xml_2.11:1.0.4 requires scala version: 2.11.4
[WARNING] Multiple versions of scala libraries detected!
[INFO] E:\git\AkkaPJ\src\test\java:-1: info: compiling
[INFO] E:\git\AkkaPJ\src\test\scala:-1: info: compiling
[INFO] Compiling 20 source files to E:\git\AkkaPJ\target\test-classes at 1517634355968
[WARNING] warning: there were 10 feature warnings; re-run with -feature for details
[WARNING] one warning found
[INFO] prepare-compile in 0 s
[INFO] compile in 4 s
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ AkkaPJ ---
[INFO] Surefire report directory: E:\git\AkkaPJ\target\surefire-reports
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom (3 KB at 1.9 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom (3 KB at 6.1 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar (37 KB at 56.6 KB/sec)
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ AkkaPJ ---
[INFO] Building jar: E:\git\AkkaPJ\target\AkkaPJ-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:3.0.0:shade (default) @ AkkaPJ ---
[INFO] Including org.scala-lang:scala-library:jar:2.11.8 in the shaded jar.
[INFO] Including org.scala-lang:scala-compiler:jar:2.11.8 in the shaded jar.
[INFO] Including org.scala-lang.modules:scala-xml_2.11:jar:1.0.4 in the shaded jar.
[INFO] Including org.scala-lang.modules:scala-parser-combinators_2.11:jar:1.0.4 in the shaded jar.
[INFO] Including org.scala-lang:scala-reflect:jar:2.11.8 in the shaded jar.
[INFO] Including com.typesafe.akka:akka-actor_2.11:jar:2.5.9 in the shaded jar.
[INFO] Including com.typesafe:config:jar:1.3.2 in the shaded jar.
[INFO] Including org.scala-lang.modules:scala-java8-compat_2.11:jar:0.7.0 in the shaded jar.
[INFO] Attaching shaded artifact.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.142 s
[INFO] Finished at: 2018-02-03T13:06:06+08:00
[INFO] Final Memory: 27M/317M
[INFO] ------------------------------------------------------------------------