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
CodePudding user response:
Select Your Project -> Popup Menu Resolve Project Problems...
Popup Window Resolve Project Problems - "your project name" Project
Project Problems:
Some dependency artifacts are not in the local repository.
Click Button Resolve...
CodePudding user response:
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.