【问题标题】:Scala and Java with Maven in default eclipseScala 和 Java 在默认的 Eclipse 中使用 Maven
【发布时间】:2015-10-31 14:41:50
【问题描述】:

是否可以使用默认的 Eclipse(Java EE 开发人员的 Eclipse IDE 或 Java 开发人员的 Eclipse IDE)来访问 java 类中的 scala 源代码?

我在 Scala 中访问 Java 代码没有问题,反之亦然,使用 Scala-IDE 而不是在默认的 eclipse 中。我可以使用以下 pom.xml 编译源代码并执行它。我的源文件夹结构是 src/main/java、src/main/scala、src/test/scala 和 src/test/java。这甚至可能还是我需要ScalaIDE?当我下载 ScalaIDE-Plugin for eclipse 并将 scala 性质添加到它正在工作的项目中时。

<dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.7</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
            </plugin>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        net.alchim31.maven
                                    </groupId>
                                    <artifactId>
                                        scala-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [3.2.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>compile</goal>
                                        <goal>add-source</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
            <!--    <execution>
                    <id>scala-test-compile</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>-->
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArgument>-proc:none</compilerArgument>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>test.JavaMain</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

    标签: java eclipse scala maven


    【解决方案1】:

    是的,你是对的,我们不需要单独使用 SCALA IDE,我们可以使用 ECLIPSE IDE 本身来完成。

    http://davidb.github.io/scala-maven-plugin/example_java.html

    【讨论】:

    • 我正在使用 scala-maven-plugin,但如果没有 scala 插件,我无法访问 Eclipse IDE 中的源代码。
    【解决方案2】:

    this question was asked before here

    使用 maven 多模块/简单项目确保您在 pom (=>classpath) 两个 eclipse/plugins/ 目录中都使用相同的 scala 库 .jar 版本

    希望对你有所帮助。

    【讨论】:

    • 在混合 Scala/java Maven 项目中,Eclipse 的 Scala IDE 使用 org.scala-lang.scala-library-Xversion.jar,如果添加 org.scala-lang.scala-library- POM中的yversion.jar或临时scala依赖,这会导致Eclipse编译出现问题,无法解析目标版本
    猜你喜欢
    • 1970-01-01
    • 2012-07-24
    • 2012-11-02
    • 2012-07-13
    • 2017-08-02
    • 2017-04-08
    • 2015-07-02
    • 2013-05-23
    • 2012-09-01
    相关资源
    最近更新 更多