既有java又有scala的maven项目

既有java又有scala的maven项目,java,eclipse,scala,maven,Java,Eclipse,Scala,Maven,我想构建一个maven项目,它同时包含java和scala源代码。 我已经在eclipse中安装了scala IDE插件,并在pom.xml中添加了“scala maven插件”,但是scala文件中java类的导入导致编译错误。 哪种IDE是构建这种混合项目的最佳IDE 项目结构如下: pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSch

我想构建一个maven项目,它同时包含java和scala源代码。 我已经在eclipse中安装了scala IDE插件,并在pom.xml中添加了“scala maven插件”,但是scala文件中java类的导入导致编译错误。 哪种IDE是构建这种混合项目的最佳IDE

项目结构如下:

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>org.apache.spark</groupId>
  <artifactId>spark-examples_2.11</artifactId>
  <version>0.0.1-SNAPSHOT</version>


<dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.7</version>
    </dependency>
</dependencies>
<build>
<pluginManagement>
    <plugins>
<!-- This plugin compiles Scala files -->
        <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>
            </executions>
        </plugin>
<!-- This plugin compiles Java files -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
<!-- This plugin adds all dependencies to JAR file during 'package' command.
Pay EXTRA attention to the 'mainClass' tag. 
You have to set name of class with entry point to program ('main' method) -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>ScalaRunner</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </pluginManagement>  
</build>
</project>

4.0.0
org.apache.spark
spark-U 2.11
0.0.1-快照
org.scala-lang
scala图书馆
2.11.7
net.alchim31.maven
scala maven插件
scala先编译
过程资源
添加源
编译
org.apache.maven.plugins
maven编译器插件
1.8
1.8
编译
编译
maven汇编插件
2.5.3
带有依赖项的jar
ScalaRunner
包裹
单一的

从代码结构来看,Scala类依赖于Java,而不是相反。然而,在Maven配置中,Scala首先被编译。将其更改为在Java类之后编译

以下插件序列适用于我的项目:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

maven编译器插件
1.8
1.8
net.alchim31.maven
scala maven插件
编译
maven汇编插件
包裹
单一的

从代码结构来看,Scala类依赖于Java,而不是相反。然而,在Maven配置中,Scala首先被编译。将其更改为在Java类之后编译

以下插件序列适用于我的项目:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

maven编译器插件
1.8
1.8
net.alchim31.maven
scala maven插件
编译
maven汇编插件
包裹
单一的

首先,您应该将Scala移动到与
默认值不同的包中
…首先,您应该将Scala移动到与
默认值不同的包中
。。。