添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In Eclipse, I created a project using Maven and added pdfbox as a dependency. Eclipse automatically rebuilt the project, and I see pdfbox-2.0.11.jar in Maven Dependencies in the package explorer.

However, in my main Java file where I intend to use this:

package my.group.project;
import org.apache.pdfbox.pdmodel.PDDocument;

Eclipse tells me "The import org cannot be resolved."

What do I do?

My pom.xml:

<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>my.group</groupId>
  <artifactId>project</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>invoices</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.11</version>
    </dependency>
  </dependencies>
</project>
                Are you using the latest jdk10? (10.0.2) If you have jdk 1.8 installed, can you try with that one?
– Tilman Hausherr
                Sep 17, 2018 at 9:16
                There are several Java SE 10 versions, it could be 10, 10.0.1, or 10.0.2. Run "java -version" on the command. To get the maven version, find the maven directory and then enter "mvn -version" there. This will also tell you the java version.
– Tilman Hausherr
                Sep 17, 2018 at 11:51

Just for clarification: I guess that the particular class is also visible if you extend the contents in the jar in the package browser, isn't it?

If that's the case could you maybe provide your pom.xml?

However, you could also try to clean the project via Project -> Clean first.. Eclipse sometimes just behaves weird as you certainly know.

Thanks. ;) So, I built a test project myself using your pom.xml that also imports the PDDocument and for me it worked perfectly fine. Does eclipse point out any build path problems? And which JRE version are you using? – lema Sep 17, 2018 at 7:54 If nothing of this works you could try to build a new Maven project by importing your pom.xml using the Maven import wizard. That's what I did. After that you could then move your sources from the old to the new project and it should work. Something seems to be corrupted in your project setup. – lema Sep 17, 2018 at 8:02 No build path problems as far as I can tell, Java SE 10.0.2, deleting project from workspace and importing as Maven project didn't change anything. – AAM111 Sep 17, 2018 at 13:44

Project --> Properties --> Maven. Uncheck the box labeled "Resolve dependencies from Workspace projects" --> Apply and Close

Right click on your project --> Maven --> Update Project... Check the boxes "Force Update of Snapshots/Releases", "Update project configuration from pom.xml", "Clean projects"

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.