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

I prototyped a PDF viewer in Intellij Idea and am trying to integrate it into a Netbeans project. I have been unable to get Netbeans to recognize the jar file that contains the classes I use.

Netbeans Version - 15.0.2, JDK version - 15, Windows 10

Here is one of the errors in the code:

From the first line of the following method:

    private void initializeFile(File file)
        PDDocument doc = PDDocument.load(file);
        // Getting/calculating screen dimensions...
        float realWidth = doc.getPage(0).getMediaBox().getWidth();
        float realHeight = doc.getPage(0).getMediaBox().getHeight();
        System.out.println("RealW, RealH: " + realWidth + ", " + realHeight);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double ratio = 0.6;
        this.height = (int) (screenSize.getHeight() * ratio);
        this.width = (int) ((height * realWidth) / realHeight);
        this.numberOfPages = doc.getNumberOfPages();
        renderer = PDFRenderer(doc);
        System.out.println("Number of pages = " + numberOfPages);

Alt-Enter on the red underline:

When I select the Search Dependency at Maven Repositories for PDFDocument, I get this:

It finds the jar file I downloaded and put in the src/java/main directory. When I click on the Add button, it works for a few seconds and then displays this in the status line: Finished retrieving dependencies from remote repositories. But the error remains, it still can't find the class PDDocument.

I tried the following command line which didn't fail but didn't remove the error.

$ mvn install:install-file -Dfile="pdfbox-app-2.0.27.jar" -DgroupId="org.apache.pdfbox" -DartifactId="pdfbox" -Dversion=2.0.27 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing E:\hg\project\MyName\src\main\pdfbox-app-2.0.27.jar to C:\Users\ME\.m2\repository\org\apache\pdfbox\pdfbox\2.0.27\pdfbox-2.0.27.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.328 s
[INFO] Finished at: 2023-01-31T10:25:05-08:00
[INFO] ------------------------------------------------------------------------

Here is the section of my pom.xml

        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.27</version>
            <type>jar</type>
        </dependency>

I've gone through all of these suggestions to no avail:

https://stackoverflow.com/questions/17693040/adding-external-jar-to-maven-project-in-netbeans

Here is the relevant section of my Project's dependencies:

Is there a log somewhere where I can see what Netbeans did behind the curtain, especially if it encountered an error? What else can I try?

Thanks

You should rework your maven project so you only use artifacts available from maven central. – Thorbjørn Ravn Andersen Feb 1 at 8:25 "It finds the jar file I downloaded and put in the src/java/main directory" is weird, it shouldn't put jar files there. It should add a dependency in the pom.xml file, and maven should do the rest when building. (You have to run the build once, I forgot to mention; the answer will do that, i.e. run a "priming build") – Tilman Hausherr Feb 1 at 8:56 @TilmanHausherr That's what I'm trying to do. If I just enter the import statement, Netbeans complains that it can't find it. Also, I tried just using the Maven search through Netbeans and it failed to find it. That's why I ran the mvn command above to add it to my local repository. – AlexHomeBrew Feb 1 at 16:36 What happens if you run the build, i.e. "mvn install" from the command line, or by right-clicking on the project and then click "build"? Are you behind a company proxy? – Tilman Hausherr Feb 2 at 3:48

The artifact is available on Maven Central (https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox/2.0.27). This mean that a well-formed Maven project with an empty local repository - no files under .m2/repository - should be able to download it and build your source.

If you cannot do that on the command line (you may have to install Maven first) then it is your code that should be fixed before trying to open in Netbeans.

If the project builds from the command line, but not in Netbeans 16 when you open the project (it should have a small M on the folder icon to indicate that a Maven project has been detected), your Netbeans installation may be broken. If so, uninstall it and reinstall a freshly downloaded copy of the appropriate installer.

Thanks @Thorbjørn Ravn Andersen. I am trying to upload a tiny version of my project to github but having login problems because I changed to 2 factor auth. Sigh. I will let you know when I get it loaded. Note that I had to deliver something so I made a screenshot and delivered it with an image panel. I still want to fix this problem for future Help items though it is a lower priority. – AlexHomeBrew Feb 11 at 0:21 @AlexHomeBrew You may want to focus on getting it to work on the command line. If you have a normal Maven project which is self-contained and does not rely on jar files being magically present on the system, Netbeans should load it. You may want to experiment with a freshly cloned copy. – Thorbjørn Ravn Andersen Feb 11 at 19:14

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.