首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >混合Scala/Java将无法编译,错误:无法访问

混合Scala/Java将无法编译,错误:无法访问
EN

Stack Overflow用户
提问于 2014-10-03 18:12:44
回答 1查看 2K关注 0票数 0

我有一个混合的scala/java项目的问题,需要编译所有的东西。我同时使用了scala-maven-plugin和maven-compiler-plugin,就像(http://davidb.github.io/scala-maven-plugin/example_java.html)这样的许多网站上所建议的那样。

产生的错误消息是(SResize是一个scala类)

代码语言:javascript
复制
[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] 

在build部分中

对于scala-maven-plugin

代码语言:javascript
复制
        <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>

对于maven编译器

代码语言:javascript
复制
        <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>
EN

回答 1

Stack Overflow用户

发布于 2014-10-04 01:48:36

它最终是一个非常奇怪的错误,最初是由于缺少scala库依赖项而导致的,这给maven编译器带来了问题(我猜是吗?)

代码语言:javascript
复制
   <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>${scala.version}</version>
    </dependency>

最后的scala-maven-plugin是

代码语言:javascript
复制
      <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编译器插件(之后)

代码语言:javascript
复制
        <!-- 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>

现在一切都编译得很完美了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26177099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档