0

我正在尝试将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 的工件描述符”,第二个错误表示未找到所述依赖项,突出显示“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
4

2 回答 2

1

请按照以下步骤操作:-

  1. 使用链接中的说明安装 MAVEN 。您也应该安装 JAVA 7 或
  2. 设置环境变量(即需要设置JAVA HOME和Maven路径)
  3. 使用maven命令验证安装成功mvn -v
  4. 如果 Maven 版本显示成功,请尝试 IntelliJ 中的自动导入功能。它应该从远程存储库下载工件
  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 主目录
于 2018-04-17T16:55:17.360 回答
0

好的,经过更多研究后,我发现 IntelliJ 基本上只是不想写入已经失败的导入文件夹。

因此,删除要导入的依赖项的文件夹C:\user\[user]\.m2\repository并重新导入应该可以解决问题。

于 2018-04-19T08:32:17.737 回答