簡體   English   中英

IDE可以使用Maven在Java中解析Scala類嗎?

[英]Possible for IDE's to resolve Scala classes in Java using Maven?

我有一個混合Java和Scala源的項目,遵循此頁面上的說明,從命令行運行Maven時可以正常工作。

但是,使用IDEA和Netbeans等IDE的人在使用Java代碼解析Scala類時遇到了問題(但不是相反,這要歸功於可用的插件)。 有辦法解決它們嗎?

注意:我可以從命令行構建就好了; Scala類在Java類之前編譯。 我只是希望IDE能夠識別這一點。 我可以為Scala類創建一個單獨的模塊來解決這個問題,但對我來說似乎有些過分。

注意:在IDEA中,我有“先編譯Scala類”,但仍然無法解決問題。

更新:以下是我正在使用的版本:scala-library 2.8.0 maven-scala-plugin 2.12 IDEA 9.0 Ultimate with plugin repos Netbeans 6.9 with scala nightly plugin的最新scala插件

您使用的是哪些版本(Scala,IDE,Scala插件)​​?

當我在9個月前開始使用Scala 2.7時,我遇到了同樣的問題。 雖然我最近沒有嘗試過混合項目,但我的理解是這些問題將在Scala 2.8中得到解決。 使用Scala 2.8嘗試Eclipse 3.5.2可能是值得的 - 我的印象是Eclipse插件跟上2.8的變化比其他IDE插件更好(但我可能是錯的)。

我一直試圖弄清楚如何使用Eclipse Indigo + Scala IDE 2.9,m2eclipse,scala 2.9 + jdk1.7的混合運氣。

我發現使用maven eclipse插件(mvn eclipse:eclipse)並將項目作為eclipse項目(不是maven項目)導入,並使用下面的自定義清理了錯誤標記。

<plugin>
    <groupId>org.scala-tools</groupId>
    <artifactId>maven-scala-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.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>

    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>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>src/test/scala</source>
                </sources>
            </configuration>
        </execution>
    </executions    
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.8</version>

    <configuration>
        <downloadSources>true</downloadSources>
        <downloadJavadocs>true</downloadJavadocs>
        <projectnatures>
            <projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
            <projectnature>org.eclipse.jdt.core.javanature</projectnature>
        </projectnatures>
        <buildcommands>
            <buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
        </buildcommands>
        <classpathContainers>
            <classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER"</classpathContainer>
            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
        </classpathContainers>
        <excludes>
            <exclude>org.scala-lang:scala-library</exclude>
            <exclude>org.scala-lang:scala-compiler</exclude>
        </excludes>
        <sourceIncludes>
            <sourceInclude>**/*.scala</sourceInclude>
            <sourceInclude>**/*.java</sourceInclude>
        </sourceIncludes>
    </configuration>
</plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM