0

I'm trying to import TOML4J into my my maven project. I added this to my dependencies in my POM.xml in the dependencies part:

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

But I get an error at

<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">

saying that it "failed to read artifact descriptor for com.moandjienzana.toml:toml4j:jar:0.7.2" and a second error that says that said dependency is not found, highlighting the "0.7.2"

EDIT 1: I believe to have fixed this issue but if I add

import com.moandjiezana.toml.toml4j;

to my main file it doesn't recognize the "moandjiezana" part.

EDIT 2: full POM.xml file here:

<?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>

EDIT 3: after doing the clean install I got this Error:

[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?

I do have the JDK installed and IntelliJ recognizes it.

EDIT 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
Cradac
  • 35
  • 7
  • Actually, I can download the above artifact from maven. Hope you have internet access to download from remote repo. – notionquest Apr 17 '18 at 11:34
  • I do have an internet connection through a proxy server. I can even ping the repository through IntelliJ. @notionquest – Cradac Apr 17 '18 at 13:49
  • IntelliJ has an auto import feature. Go to Settings --> Search for "auto-import". Enable it. Once done, IntelliJ should automatically get the dependencies from repo. – notionquest Apr 17 '18 at 14:03
  • It was already enabled but it still didn't work. Sorry if I'm acting stupid but I'm fairly new to using maven. – Cradac Apr 17 '18 at 14:34
  • Have you installed the Maven on your computer? Are you using windows or Mac? Did you set the MAVEN environment variable correctly? Is this your first Maven project in your computer? – notionquest Apr 17 '18 at 16:27
  • I use maven as it came (preinstalled to my knowledge) with IntelliJ IDEA. I have a windows PC, I set no variables if it didn't do that automatically and, yes, it is my first maven project. – Cradac Apr 17 '18 at 16:31
  • Also it can't be a problem with the Proxy Server as I'm currently trying it in my home network. – Cradac Apr 17 '18 at 16:32
  • IntelliJ doesn't install the Maven software. It just has plugins to work with Maven and other build softwares (like SBT). You may need to install the maven. Please follow this link https://maven.apache.org/install.html to install Maven (and set the env variables correctly). Then, try it. It should work. – notionquest Apr 17 '18 at 16:35
  • edit: I installed maven seperately now and added it to the PATH variable. mvn -v responds – Cradac Apr 17 '18 at 16:54
  • Good. Now go to IntelliJ, open POM file, right click and select "Maven --> Reimport". It should download the artifact. – notionquest Apr 17 '18 at 16:56
  • It now says again that it "failed to read the artifact descriptor for com.moandjiezana.toml:toml4j:jar:0.7.2" – Cradac Apr 17 '18 at 17:02
  • Can you please add your full POM file in the OP? Also, please try this command "mvn clean install" on the project directory? – notionquest Apr 17 '18 at 17:03
  • I added it and got the Error as stated in OP. I feel like this is a simple error but I just can't find it... – Cradac Apr 17 '18 at 17:13
  • Looks like you have set the JAVA_HOME incorrectly. It would be something like this JAVA_HOME=C:\Program Files\Java\jdk1.8.0_31. Use set JAVA_HOME=. Then, try mvn clean install. Refer this post https://stackoverflow.com/questions/19655184/no-compiler-is-provided-in-this-environment-perhaps-you-are-running-on-a-jre-ra – notionquest Apr 17 '18 at 17:26
  • Thank you! It actually wasn't even set in the first place. Starting to compile works now. I get a new error message though (see OP) – Cradac Apr 17 '18 at 17:33
  • I think the original issue is resolved now. It would be great if you can accept this answer and open a new issue for the new problem (for better clarity). – notionquest Apr 17 '18 at 20:17
  • It isn't solved yet. I still get the same error (failed to read artifact descriptor) at the project tag. – Cradac Apr 18 '18 at 08:03
  • Alright. After anothe rfew hours of trying out every combination of setting I finally got it to work. Thanks for the help @notionquest ! – Cradac Apr 18 '18 at 11:35

2 Answers2

1

Please follow the below steps:-

  1. Install MAVEN using the instructions in the link. You should have JAVA 7or installed as well
  2. Set the environment variables (i.e. JAVA HOME and Maven path should be set)
  3. Verify the successful installation using the maven command mvn -v
  4. If the Maven version is displayed successfully, then try the auto import feature in IntelliJ. It should download the artifact from remote repository
  5. Go to IntelliJ
  6. Open POM xml file --> Right click --> Maven --> Reimport

Edit:-

  1. Please ensure that JDK 7 or 8 is installed and JAVA_HOME is set correctly
  2. Use set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_31 to set the Java home correctly
notionquest
  • 37,595
  • 6
  • 111
  • 105
0

Okay after some more research I found that IntelliJ basically just didn't want to write into an already failed import folder.

So deleting the folder of the dependency you want to import in C:\user\[user]\.m2\repository and doing a reimport should fix the problem.

Cradac
  • 35
  • 7