Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven

huangapple go评论76阅读模式
英文:

Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven

问题

我对Maven还不太熟悉,但我想使用它来运行一个简单的deeplearning4j程序。在添加了所有必要的依赖项后,我得到了以下错误:

Error:java: 不支持版本 5 的发布

在按照[此页面](https://dev.to/techgirl1908/intellij-error-java-release-version-5-not-supported-376)上的说明进行操作后(更改我的SDK、语言和目标字节码为11),我得到了以下错误:

Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven

Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven

我遇到了这个问题:
Error:java: java.lang.ExceptionInInitializerError
com.sun.tools.javac.code.TypeTags
Error:java: java.lang.ExceptionInInitializerError

我还尝试了设置JDK 14,但是我得到了相同的错误。这是我的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
    <artifactId>Deep</artifactId>
    <version>1.0-SNAPSHOT</version>
    
    <properties>
        <maven.compiler.source>1.11</maven.compiler.source>
        <maven.compiler.target>1.11</maven.compiler.target>
        <dl4j.version>0.9.1</dl4j.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-native-platform</artifactId>
            <version>${dl4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-core</artifactId>
            <version>${dl4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.datavec</groupId>
            <artifactId>datavec-api</artifactId>
            <version>${dl4j.version}</version>
        </dependency>
        
        <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-api</artifactId>
            <version>1.0.0-beta3</version>
        </dependency>
        
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-play_2.11</artifactId>
            <version>0.9.1</version>
        </dependency>
        
    </dependencies>

</project>

如果有人能够解释一下我可能做错了什么,我将不胜感激。

英文:

I'm new to maven but I would like to use it to run simple deeplearing4j program. After adding all the necessary dependencies I get the following: <br><br>
Error:java: release version 5 not supported<br><br>
After following the instructions at this page (changing my SDK, language and target byte code to 11)<br><br>
Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven <br><br>
Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven

I'm getting this:<br><br>

Error:java: java.lang.ExceptionInInitializerError
com.sun.tools.javac.code.TypeTags
Error:java: java.lang.ExceptionInInitializerError

I've also tried setting JDK 14 but I get the same error. Here is my pom.xml file:<br><br>

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;org.example&lt;/groupId&gt;
    &lt;artifactId&gt;Deep&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    
    &lt;properties&gt;
        &lt;maven.compiler.source&gt;1.11&lt;/maven.compiler.source&gt;
        &lt;maven.compiler.target&gt;1.11&lt;/maven.compiler.target&gt;
        &lt;dl4j.version&gt;0.9.1&lt;/dl4j.version&gt;
    &lt;/properties&gt;

    &lt;dependencies&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.nd4j&lt;/groupId&gt;
            &lt;artifactId&gt;nd4j-native-platform&lt;/artifactId&gt;
            &lt;version&gt;${dl4j.version}&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.deeplearning4j&lt;/groupId&gt;
            &lt;artifactId&gt;deeplearning4j-core&lt;/artifactId&gt;
            &lt;version&gt;${dl4j.version}&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.datavec&lt;/groupId&gt;
            &lt;artifactId&gt;datavec-api&lt;/artifactId&gt;
            &lt;version&gt;${dl4j.version}&lt;/version&gt;
        &lt;/dependency&gt;
        
        &lt;dependency&gt;
            &lt;groupId&gt;org.nd4j&lt;/groupId&gt;
            &lt;artifactId&gt;nd4j-api&lt;/artifactId&gt;
            &lt;version&gt;1.0.0-beta3&lt;/version&gt;
        &lt;/dependency&gt;
        
        &lt;dependency&gt;
            &lt;groupId&gt;org.deeplearning4j&lt;/groupId&gt;
            &lt;artifactId&gt;deeplearning4j-play_2.11&lt;/artifactId&gt;
            &lt;version&gt;0.9.1&lt;/version&gt;
        &lt;/dependency&gt;
        
    &lt;/dependencies&gt;

&lt;/project&gt;

If anybody can shed some light on what I might be doing wrong here I would appreciate it.

答案1

得分: 55

这是错误的。

&lt;maven.compiler.source&gt;1.11&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.11&lt;/maven.compiler.target&gt;

在 Java 1.9 之后,版本命名已更改。在 pom.xml 中进行以下更改。

&lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;

从 Java 10 开始遵循相同的约定。

实际问题是:库中的一个依赖 org.deeplearning4j:deeplearning4j-core:jar:0.9.1:compile,此 jar 依赖于 org.projectlombok:lombok:jar:1.16.16:compile

所以这是 Lombok 的一个问题,在后续版本中他们进行了修复。要查看所有传递依赖项,您可以运行 mvn dependency:tree 命令,查看您引入的库的所有传递依赖项。

我在 pom 中添加了以下依赖项,解决了这个问题。

&lt;dependency&gt;
  &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
  &lt;artifactId&gt;lombok&lt;/artifactId&gt;
  &lt;version&gt;1.18.2&lt;/version&gt;
  &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
英文:

This is wrong.

&lt;maven.compiler.source&gt;1.11&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.11&lt;/maven.compiler.target&gt;

Post Java 1.9, the version naming has changed. Make the following changes in the pom.xml.

&lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;

The same convention follows from 10+ Java version.

The real issue is: one of library org.deeplearning4j:deeplearning4j-core:jar:0.9.1:compile this jar having a dependency on org.projectlombok:lombok:jar:1.16.16:compile.

So this was an issue with Lombok which they fixed in a later version. To see all transitive dependencies you can do a mvn dependency:tree and see all transitive dependencies of the libraries you have brought in.

I have included the below dependency in the pom and that resolved the issue.

&lt;dependency&gt;
  &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
  &lt;artifactId&gt;lombok&lt;/artifactId&gt;
  &lt;version&gt;1.18.2&lt;/version&gt;
  &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;

答案2

得分: 17

将以下内容添加到 pom.xml 文件中:

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.18.20</version>
  <scope>provided</scope>
</dependency>
英文:

Add this to pom.xml:

&lt;dependency&gt;
  &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
  &lt;artifactId&gt;lombok&lt;/artifactId&gt;
  &lt;version&gt;1.18.20&lt;/version&gt;
  &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;

答案3

得分: 12

可能是因为在运行IntelliJ应用程序时没有在IDE中配置项目SDK设置,导致出现这些问题。

英文:

It could be a reason of getting this issues while running application Intellij that you haven't configuration Project SDK setting in IDE.

Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven

答案4

得分: 9

我在使用JDK 10编译Java 8源代码时也遇到了这个错误。

更改环境变量JAVA_HOME为JDK 8的安装目录后,这个错误消失了。

英文:

I also got this error, when using jdk 10 to compile java8 source code.

Error:java: java.lang.ExceptionInInitializerError com.sun.tools.javac.code.TypeTags when trying to run maven

After changing environment variable JAVA_HOME to jdk8 home dir, this error disappear.

答案5

得分: 1

如果您在使用jdk8运行项目仍然遇到相同的错误,请按照以下2个步骤操作:

  1. 检查您是否能够从IntelliJ的maven工具栏中执行您的maven项目,而不是从终端中执行。
  2. 如果您的项目构建成功,请检查您的JAVA_HOME是否设置正确。(在我的情况下,我从bash切换到了zsh,而JAVA_HOME未设置)。
英文:

If you're using jdk8 to run your project and still face the same error.
Please follow the following 2 steps.

  1. check whether you're able to execute your maven project from IntelliJ's maven bar, instead of from the terminal.
  2. If your project builds then check whether your JAVA_HOME is setup correctly. (In my case I switched from bash to zsh, and JAVA_HOME. was not setup)

答案6

得分: 0

我也遇到过那个问题。
检查JAVA_HOME变量。对于Ubuntu,请在终端中输入echo $JAVA_HOME。如果你看到这个和java -version之间的差异,你需要将合适的JDK版本设置到你的JAVA_HOME,就像下面这样:
export JAVA_HOME=YOUR_JDK_BIN_PATH

英文:

I have also faced that problem.
Check the JAVA_HOME variable. For ubuntu, go to the terminal and write echo $JAVA_HOME. If you see the difference between this and java -version you will need to set the appropriate version of JDK to your JAVA_HOME like below
export JAVA_HOME=YOUR_JDK_BIN_PATH.

答案7

得分: 0

我遇到了类似的问题,通过将JDK版本从11更改为8,我成功解决了。顺便说一下,这并不是在JDK 11中以8模式运行。实际上,您需要一个JDK 8捆绑包。

英文:

I had a similar issue and I was able to solve by changing JDK version from 11 to 8. By the way, this is not running in 8 mode using JDK 11. You actually need a JDK 8 bundle.

huangapple
  • 本文由 发表于 2020年8月16日 22:56:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63438329.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定