zoukankan      html  css  js  c++  java
  • 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:gitAkkaPJ arget
    [INFO]
    [INFO] --- build-helper-maven-plugin:3.0.0:add-source (add-source) @ AkkaPJ ---
    [INFO] Source directory: E:gitAkkaPJsrcmainjava added.
    [INFO] Source directory: E:gitAkkaPJsrcmainscala added.
    [INFO]
    [INFO] --- build-helper-maven-plugin:3.0.0:add-test-source (add-test-source) @ AkkaPJ ---
    [INFO] Test Source directory: E:gitAkkaPJsrc estjava added.
    [INFO] Test Source directory: E:gitAkkaPJsrc estscala 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:gitAkkaPJ argetclasses
    [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:gitAkkaPJsrcmainjava:-1: info: compiling
    [INFO] E:gitAkkaPJsrcmainscala:-1: info: compiling
    [INFO] Compiling 5 source files to E:gitAkkaPJ argetclasses 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:gitAkkaPJ arget est-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:gitAkkaPJsrc estjava:-1: info: compiling
    [INFO] E:gitAkkaPJsrc estscala:-1: info: compiling
    [INFO] Compiling 20 source files to E:gitAkkaPJ arget est-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:gitAkkaPJ argetsurefire-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:gitAkkaPJ argetAkkaPJ-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] ------------------------------------------------------------------------

  • 相关阅读:
    pat1038. Recover the Smallest Number (30)
    pat1037. Magic Coupon (25)
    pat1036. Boys vs Girls (25)
    pat1031. Hello World for U (20)
    pat1030. Travel Plan (30)
    pat1028. List Sorting (25)
    pat1027. Colors in Mars (20)
    pat1017. Queueing at Bank (25)
    pat1025. PAT Ranking (25)
    Reverse Linked List II
  • 原文地址:https://www.cnblogs.com/AK47Sonic/p/8409216.html
Copyright © 2011-2022 走看看