Eclipse无法识别Scala源目录

时间:2014-05-21 21:47:01

标签: eclipse scala maven scala-ide

我从http://alchim31.free.fr/m2e-scala/update-site/安装了Maven Scala支持,并使用Eclipse Marketplace安装了Scala IDE插件。我可以使用mvn compile命令行构建项目。 Eclipse很好地突出了Scala代码,如果我导入项目它正确识别它的Scala自然。但它并没有将src/main/scala识别为源文件夹,也没有构建项目。

这是我的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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.examples.scala</groupId>
    <artifactId>scala-examples</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.10.3</version>
        </dependency>
    </dependencies>
</project>

我做错了什么? pom有问题吗?

作为解决方法,我手动将src/main/scala设置为源文件夹(右键单击,构建路径|用作源文件夹)。但这并不好,我想找到真正的解决方案,以便在作为Maven项目进行干净导入时正确设置项目。

更新

只需添加add-source目标+更新Maven项目即可:

<goals>
    <goal>add-source</goal>
    <goal>compile</goal>
    <goal>testCompile</goal>
</goals>

2 个答案:

答案 0 :(得分:3)

java-maven-plugin类似,有addSource目标可让您定义源和测试目录。你可以这样做:

<plugin>
    <groupId>org.scala-tools</groupId>
    <artifactId>maven-scala-plugin</artifactId>
    <version>2.15.2</version>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>testCompile</goal>
            </goals>
        </execution>
        <execution>
            <goals>
                <goal>add-source</goal>
                <configuration>
                   <sourceDir>src/main/scala</sourceDir>
                    <testSourceDir>src/main/test</testSourceDir>
                 </configuration>
            </goals>
        </execution>
    </executions>
</plugin>

我在此link

中找到了相关文档

答案 1 :(得分:1)

最新插件版本的复制粘贴代码段:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.1.3</version>
    <executions>
         <execution>
              <goals>
                   <goal>add-source</goal>
                   <goal>compile</goal>
                   <goal>testCompile</goal>
              </goals>
         </execution>
    </executions>
</plugin>

参考:http://scala-ide.org/docs/tutorials/m2eclipse/ + @Dimitri回答