in Education by
When installing PDFBox with Maven, it places the libraries in the ~/.m2/repository directory. My program complies fine with mvn package. When I try to run it with java -cp target/java-project-1.0-SNAPSHOT.jar com.example.sub.App then I get Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/PDDocument Should I also be specifying the libraries in ~/.m2/repository as part of the classpath? This seems a bit too tedious to do it this way. What is the recommended way to specify the classpath of my PDFBox library while using the library location(s) of Maven? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I wasn't able to find a nice solution with leaving the JAR files in ~/.m2, so the answer below is a workaround based on some other answers. I will be including more clarification though for those who are new to both PDFBox and maven as I am. 1) Add the following to your pom.xml file. If you already have a and section, just add the section below to that. Otherwise you may need to add the whole code below within the element: maven-assembly-plugin true **REPLACE THIS WITH THE FULL URI OF YOUR MAIN CLASS** jar-with-dependencies make-my-jar-with-dependencies package single 2) Make sure that you replace the text in the element to match the situation. For example, if your main() method is located in an App class in App.js, and your package name is com.example.sub. Then the above element should read: com.example.sub.App 3) To compile your app, run mvn package Note: I have seen some references online using mvn clean compile assembly:single instead of mvn package. I am not sure what the purpose of this is when mvn package seems to run just fine for me. This will take your project and all of your dependencies and create a single JAR file in the target directory called something like this: java-project-1.0-SNAPSHOT-jar-with-dependencies.jar 4) To run the project you can do this: java -cp target/java-project-1.0-SNAPSHOT-jar-with-dependencies.jar com.example.sub.App Make sure that you modify the above line to it your situation. In other words you may need to change both the name of the jar file and the name of the URI for your main class.

Related questions

0 votes
    I am creating a maven project from scratch, first just learn how to use maven. The main project contains ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am creating a maven project from scratch, first just learn how to use maven. The main project contains ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How to deal with "java.lang.OutOfMemoryError: Java heap space" error ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I get an java.lang.OutOfMemoryError: GC overhead limit exceeded when run gradle on Android 1.4 ... ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    I have a 2 column (1 int and 1 double) dataframe "fit_comparison", of predicted values and linear ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    what configuration needs to be tweaked, and where does it live, in order to increase the maximum allowed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    what configuration needs to be tweaked, and where does it live, in order to increase the maximum allowed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I am trying to deploy our eRCP (embedded Rich Client Platform) application on a Windows CE5 Professional ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I am trying to deploy our eRCP (embedded Rich Client Platform) application on a Windows CE5 Professional ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I am using simple thread to execute the httpGet to server when a button is clicked, but I get ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    Which of these classes is not included in java.lang? (a) Byte (b) Integer (c) Array (d) Class ... java programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Maven command to create Java project is ____________. A. mvn archetype:generate -groupId=com.play ... artifactId=cucumber-jvm-maven -DarchetypeArtifactId=maven-archetype-quickstart...
asked Dec 13, 2022 in Technology by JackTerrance
0 votes
    Can you explain the Maven build lifecycle?...
asked Feb 5, 2023 in Technology by JackTerrance
0 votes
    What is the difference between Maven and ANT?...
asked Feb 5, 2023 in Technology by JackTerrance
0 votes
    How does Maven manage dependencies?...
asked Feb 5, 2023 in Technology by JackTerrance
...