Reputation: 193
I have a project managed by Maven which I am trying to get to work in Eclipse. The problem is that all the dependencies which are being managed by Maven are not accessible inside the Java code.
In Eclipse I get an error on the imports for the respective classes:
The type org.apache.commons.math3.util.Pair is not accessible
while when I try to build the project with Maven I get the error:
package org.apache.commons.math3.util is not visible (package org.apache.commons.math3.util is declared in the unnamed module, but module org.apache.commons.math3.util does not read it)
The dependencies have been downloaded by Maven and I can find them in the .m2 folder. I can even see the jar files when looking at the Java build path in Eclipse.
I also get the same error when I try to use Maven through the command line.
Does anyone know why this could be happening?
Upvotes: 5
Views: 4518
Reputation: 1
I was facing the same issue. I created a new project with all same classes but my new project was not accessing any maven libraries.
In Visual Studio code when you create a new javaFX project, it generates These files in which module-info.java
contains these values. My project doesn't include fxml file so I was adding dependencies to pom.xml file .
So comparing it to the old project I deleted module-info.java
file and all my The package xyz is not accessible errors are gone.
Upvotes: 0
Reputation: 18304
The other answers here didn't fix this for me. Instead it was a classpath clash, due to an "uberjar".
In the classpath were both:
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.7.0</version>
</dependency>
And
<dependency>
<groupId>org.neo4j.procedure</groupId>
<artifactId>apoc</artifactId>
<version>4.2.0.11</version>
<classifier>core</classifier>
</dependency>
The latter one is an uberjar, which also contains all the same classes from the former. Somehow Eclipse can't cope with this.
The fix was to re-compile apoc
without this dependency in the uberjar.
Upvotes: 0
Reputation: 21
I had an incomplete module-info.java file : removing this fixed my problems. I imagine setting this properly would also have worked but I need to understand module files.
Upvotes: 2
Reputation: 193
I managed to fix it. I don't know why but by not creating the module-info.java file when eclipse asked me, everything worked just fine.
Upvotes: 7
Reputation: 618
one time it happened to me too. Looks like a permission issue in my case or a disk space problem.
Also, try to delete the dependency from te disk and run mvn clean install
again.
Make sure you're using an up-to-date maven version and perform ALT+F5 + force maven dependency update.
Upvotes: 0