Scala和Java混合项目搭建:(Eclipse)

 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.0</modelVersion>

    <groupId>com.citi.sky</groupId>
    <artifactId>AkkaPJ</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AkkaPJ</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jdk.version>1.8</jdk.version>
        <scala.version>2.11.8</scala.version>
        <akka.version>2.5.9</akka.version>
        <scalatest.version>3.0.4</scalatest.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
        </dependency>

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-reflect</artifactId>
            <version>${scala.version}</version>
        </dependency>

        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.11</artifactId>
            <version>${akka.version}</version>

        </dependency>

        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-testkit_2.11</artifactId>
            <version>${akka.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.11</artifactId>
            <version>${scalatest.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${basedir}/src/main/java</source>
                                <source>${basedir}/src/main/scala</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-test-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${basedir}/src/test/java</source>
                                <source>${basedir}/src/test/scala</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-resource</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/resources</directory>
                                    <filtering>true</filtering>
                                    <excludes>
                                        <exclude>**/*.java</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-test-resource</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-test-resource</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/test/resources</directory>
                                    <filtering>true</filtering>
                                    <excludes>
                                        <exclude>**/*.java</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>allInOne</shadedClassifierName>
                            <artifactSet>
                                <includes>
                                    <include>*:*</include>
                                </includes>
                            </artifactSet>

                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.citi.dw.client.ClientTest</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--< build circular dependencies between Java and Scala> -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.3.1</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>${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] ------------------------------------------------------------------------

 

posted @ 2018-02-03 13:09  AK47Sonic  阅读(1666)  评论(0编辑  收藏  举报