2014-10-03 83 views
0

我有一個混合的Scala/Java項目的問題,並得到一切編譯。我正在使用像許多網站(如http://davidb.github.io/scala-maven-plugin/example_java.html)中的scala-maven-plugin和maven-compiler-plugin。混合Scala/Java無法編譯,錯誤:無法訪問

所得錯誤消息是(SResize是一個階類)

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project tipl-spark: Compilation failure 
[ERROR] error: cannot access SResize$sstats$4$ 
[ERROR] -> [Help 1] 
[ERROR] 

在生成部

爲階-行家-插件

 <plugin> 
      <groupId>net.alchim31.maven</groupId> 
      <artifactId>scala-maven-plugin</artifactId> 
      <version>3.2.0</version> 
      <executions> 

       <execution> 
        <id>scala-compile-first</id> 
        <phase>process-resources</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      <execution> 
       <id>attach-scaladocs</id> 
       <phase>verify</phase> 
       <goals> 
        <goal>doc-jar</goal> 
       </goals> 
      </execution> 
     </executions> 
      <configuration> 
       <scalaVersion>${scala.version}</scalaVersion> 
       <source>${java.version}</source> 
       <target>${java.version}</target> 
       <encoding>UTF-8</encoding> 
       <args> 
        <arg>-unchecked</arg> 
        <arg>-deprecation</arg> 
        <arg>-feature</arg> 
        <arg>-language:postfixOps</arg> 
       </args> 
       <jvmArgs> 
        <jvmArg>${java.memory.min}</jvmArg> 
        <jvmArg>${java.memory.max}</jvmArg> 
        <jvmArg>-XX:PermSize=${PermGen}</jvmArg> 
        <jvmArg>-XX:MaxPermSize=${MaxPermGen}</jvmArg> 
       </jvmArgs> 

      </configuration> 
     </plugin> 

的行家編譯

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>${java.version}</source> 
       <target>${java.version}</target> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>compile</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
+0

如果scala項目不依賴於java,那麼嘗試分別構建它們並將構建好的scala.jar導入到java項目中 – AntJavaDev 2014-10-03 11:21:22

回答

0

它結束了由在一開始就缺少Scala庫的依賴這是造成了Maven的編譯器的問題(我猜?)

<dependency> 
     <groupId>org.scala-lang</groupId> 
     <artifactId>scala-library</artifactId> 
     <version>${scala.version}</version> 
    </dependency> 

最終斯卡拉,Maven的插件是

一個很奇怪的錯誤
 <plugin> 
      <groupId>net.alchim31.maven</groupId> 
      <artifactId>scala-maven-plugin</artifactId> 
      <version>3.2.0</version> 
      <executions> 

       <execution> 
        <id>scala-compile-first</id> 
        <phase>process-resources</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      <execution> 
       <id>attach-scaladocs</id> 
       <phase>verify</phase> 
       <goals> 
        <goal>doc-jar</goal> 
       </goals> 
      </execution> 
     </executions> 
      <configuration> 
       <scalaVersion>${scala.compile.version}</scalaVersion> 
       <source>${java.version}</source> 
       <target>${java.version}</target> 
       <encoding>UTF-8</encoding> 
       <args> 
        <arg>-unchecked</arg> 
        <arg>-deprecation</arg> 
        <arg>-feature</arg> 
        <arg>-language:postfixOps</arg> 
       </args> 
       <jvmArgs> 
        <jvmArg>${java.memory.min}</jvmArg> 
        <jvmArg>${java.memory.max}</jvmArg> 
        <jvmArg>-XX:PermSize=${PermGen}</jvmArg> 
        <jvmArg>-XX:MaxPermSize=${MaxPermGen}</jvmArg> 
       </jvmArgs> 
       <javacArgs> 
        <javacArg>-source</javacArg> 
        <javacArg>${java.version}</javacArg> 
        <javacArg>-target</javacArg> 
        <javacArg>${java.version}</javacArg> 
       </javacArgs> 

      </configuration> 
     </plugin> 

具有以下Maven的編譯器插件(事後)

 <!-- use the the maven compiler plugin settings from http://davidb.github.io/scala-maven-plugin/example_java.html --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>${java.version}</source> 
       <target>${java.version}</target> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>compile</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

現在一切都完美編譯