gpt4 book ai didi

java - Java 中导入 toml4j 失败

转载 作者:行者123 更新时间:2023-12-02 11:21:42 31 4
gpt4 key购买 nike

我正在尝试导入TOML4J进入我的 Maven 项目。我将其添加到 POM.xml 中依赖项部分的依赖项中:

<dependency>
<groupId>com.moandjiezana.toml</groupId>
<artifactId>toml4j</artifactId>
<version>0.7.2</version>
</dependency>

但是我在

处收到错误
<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">

说它“无法读取 com.moandjienzana.toml:toml4j:jar:0.7.2 的 Artifact 描述符”第二个错误表明未找到所述依赖项,突出显示“0.7.2”

编辑1:我相信已经解决了这个问题,但是如果我添加

import com.moandjiezana.toml.toml4j;

对于我的主文件,它无法识别“moandjiezana”部分。

编辑 2:完整的 POM.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<!--suppress MavenModelInspection -->
<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>com.comp.ima.restmesspc</groupId>
<artifactId>RESTMessPC</artifactId>
<version>0.1-SNAPSHOT</version>

<name>RESTMessPC</name>
<!-- FIXME change it to the project's website -->
<url>http://www.maven.apache.org.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.moandjiezana.toml/toml4j -->
<dependency>
<groupId>com.moandjiezana.toml</groupId>
<artifactId>toml4j</artifactId>
<version>0.7.2</version>
</dependency>

</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

编辑3:执行全新安装后,我收到此错误:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on
a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.301 s
[INFO] Finished at: 2018-04-17T19:08:28+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
7.0:compile (default-compile) on project RESTMessPC: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on
a JRE rather than a JDK?

我确实安装了 JDK 并且 IntelliJ 可以识别它。

编辑4:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Environments/Java/restmesspc/src/main/java/com/comp/ima/restmess
pc/App.java:[8,29] cannot find symbol
symbol: class toml4j
location: package com.moandjiezana.toml
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.432 s
[INFO] Finished at: 2018-04-17T19:30:39+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
7.0:compile (default-compile) on project RESTMessPC: Compilation failure
[ERROR] /D:/Environments/Java/restmesspc/src/main/java/com/comp/ima/restmess
pc/App.java:[8,29] cannot find symbol
[ERROR] symbol: class toml4j
[ERROR] location: package com.moandjiezana.toml

最佳答案

请按照以下步骤操作:-

  1. 使用link中的说明安装MAVEN 。您应该还安装了 JAVA 7
  2. 设置环境变量(即设置JAVA HOME和Maven路径)
  3. 使用maven命令验证安装是否成功mvn -v
  4. 如果 Maven 版本显示成功,请尝试 IntelliJ 中的自动导入功能。它应该从远程存储库下载 Artifact
  5. 前往 IntelliJ
  6. 打开 POM xml 文件 --> 右键单击​​ --> Maven --> 重新导入

编辑:-

  1. 请确保安装了 JDK 7 或 8 并正确设置了 JAVA_HOME
  2. 使用 set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_31 正确设置 Java 主目录

关于java - Java 中导入 toml4j 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49873264/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com