PDFBox with Maven - java.lang.NoClassDefFoundErrorHow can I create an executable JAR with dependencies using Maven?How can I create an executable JAR with dependencies using Maven?Force maven updateHow to add local jar files to a Maven project?What exactly is a Maven Snapshot and why do we need it?Maven's target jar is not runningDealing with “Xerces hell” in Java/Maven?Maven is not working in Java 8 when Javadoc tags are incompleteSpecifying java version in maven - differences between properties and compiler pluginExecuting project in terminal gives NoClassDefFoundErrorException in thread “main” java.lang.NoClassDefFoundError: In Intellij [Spring boot]

If a person had control of every single cell of their body, would they be able to transform into another creature?

Why are C64 games inconsistent with which joystick port they use?

Integrating an absolute function using Mathematica

How to prevent bad sectors?

Employer demanding to see degree after poor code review

Where is the logic in castrating fighters?

Flying domestically in the US, is my State Issued ID all I need to get past security?

Full backup on database creation

Crossing US border with music files I'm legally allowed to possess

Can R-3-methyl-4-heptanone be enantioselectively synthesised from 4-heptanone?

Why colon to denote that a value belongs to a type?

Were pens caps holes designed to prevent death by suffocation if swallowed?

How were these pictures of spacecraft wind tunnel testing taken?

Identify this in soil?

Using the smallest number of bytes of code, write a program that produces this image

Why is this Simple Puzzle impossible to solve?

Is floating in space similar to falling under gravity?

What are these arcade games in Ghostbusters 1984?

Could a 19.25mm revolver actually exist?

Employer asking for online access to bank account - Is this a scam?

Is it possible to play as a necromancer skeleton?

Is the Indo-European language family made up?

How can people dance around bonfires on Lag Lo'Omer - it's darchei emori?

Placing bypass capacitors after VCC reaches the IC



PDFBox with Maven - java.lang.NoClassDefFoundError


How can I create an executable JAR with dependencies using Maven?How can I create an executable JAR with dependencies using Maven?Force maven updateHow to add local jar files to a Maven project?What exactly is a Maven Snapshot and why do we need it?Maven's target jar is not runningDealing with “Xerces hell” in Java/Maven?Maven is not working in Java 8 when Javadoc tags are incompleteSpecifying java version in maven - differences between properties and compiler pluginExecuting project in terminal gives NoClassDefFoundErrorException in thread “main” java.lang.NoClassDefFoundError: In Intellij [Spring boot]






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















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?










share|improve this question



















  • 1





    Possible duplicate of How can I create an executable JAR with dependencies using Maven?

    – Roland Weisleder
    Mar 24 at 8:20











  • Your classpath (-cp) only has your own project, not the dependencies.

    – Mark Rotteveel
    Mar 24 at 8:41











  • I just them in the lib subdir and add that one to the classpath but I don't know if it is best practice.

    – Tilman Hausherr
    Mar 24 at 20:24

















1















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?










share|improve this question



















  • 1





    Possible duplicate of How can I create an executable JAR with dependencies using Maven?

    – Roland Weisleder
    Mar 24 at 8:20











  • Your classpath (-cp) only has your own project, not the dependencies.

    – Mark Rotteveel
    Mar 24 at 8:41











  • I just them in the lib subdir and add that one to the classpath but I don't know if it is best practice.

    – Tilman Hausherr
    Mar 24 at 20:24













1












1








1


1






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?










share|improve this question
















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?







java maven pdfbox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 0:32







kojow7

















asked Mar 24 at 6:52









kojow7kojow7

3,49042568




3,49042568







  • 1





    Possible duplicate of How can I create an executable JAR with dependencies using Maven?

    – Roland Weisleder
    Mar 24 at 8:20











  • Your classpath (-cp) only has your own project, not the dependencies.

    – Mark Rotteveel
    Mar 24 at 8:41











  • I just them in the lib subdir and add that one to the classpath but I don't know if it is best practice.

    – Tilman Hausherr
    Mar 24 at 20:24












  • 1





    Possible duplicate of How can I create an executable JAR with dependencies using Maven?

    – Roland Weisleder
    Mar 24 at 8:20











  • Your classpath (-cp) only has your own project, not the dependencies.

    – Mark Rotteveel
    Mar 24 at 8:41











  • I just them in the lib subdir and add that one to the classpath but I don't know if it is best practice.

    – Tilman Hausherr
    Mar 24 at 20:24







1




1





Possible duplicate of How can I create an executable JAR with dependencies using Maven?

– Roland Weisleder
Mar 24 at 8:20





Possible duplicate of How can I create an executable JAR with dependencies using Maven?

– Roland Weisleder
Mar 24 at 8:20













Your classpath (-cp) only has your own project, not the dependencies.

– Mark Rotteveel
Mar 24 at 8:41





Your classpath (-cp) only has your own project, not the dependencies.

– Mark Rotteveel
Mar 24 at 8:41













I just them in the lib subdir and add that one to the classpath but I don't know if it is best practice.

– Tilman Hausherr
Mar 24 at 20:24





I just them in the lib subdir and add that one to the classpath but I don't know if it is best practice.

– Tilman Hausherr
Mar 24 at 20:24












1 Answer
1






active

oldest

votes


















1














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 <build> and <plugins> section, just add the <plugin> section below to that. Otherwise you may need to add the whole code below within the <project> element:



 <build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>**REPLACE THIS WITH THE FULL URI OF YOUR MAIN CLASS**</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


2) Make sure that you replace the text in the <mainClass> 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:



<mainClass>com.example.sub.App</mainClass>


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.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321401%2fpdfbox-with-maven-java-lang-noclassdeffounderror%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    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 <build> and <plugins> section, just add the <plugin> section below to that. Otherwise you may need to add the whole code below within the <project> element:



     <build>
    <plugins>
    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
    <archive>
    <manifest>
    <addClasspath>true</addClasspath>
    <mainClass>**REPLACE THIS WITH THE FULL URI OF YOUR MAIN CLASS**</mainClass>
    </manifest>
    </archive>
    <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    </configuration>
    <executions>
    <execution>
    <id>make-my-jar-with-dependencies</id>
    <phase>package</phase>
    <goals>
    <goal>single</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>


    2) Make sure that you replace the text in the <mainClass> 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:



    <mainClass>com.example.sub.App</mainClass>


    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.






    share|improve this answer





























      1














      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 <build> and <plugins> section, just add the <plugin> section below to that. Otherwise you may need to add the whole code below within the <project> element:



       <build>
      <plugins>
      <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
      <archive>
      <manifest>
      <addClasspath>true</addClasspath>
      <mainClass>**REPLACE THIS WITH THE FULL URI OF YOUR MAIN CLASS**</mainClass>
      </manifest>
      </archive>
      <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
      </configuration>
      <executions>
      <execution>
      <id>make-my-jar-with-dependencies</id>
      <phase>package</phase>
      <goals>
      <goal>single</goal>
      </goals>
      </execution>
      </executions>
      </plugin>
      </plugins>
      </build>


      2) Make sure that you replace the text in the <mainClass> 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:



      <mainClass>com.example.sub.App</mainClass>


      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.






      share|improve this answer



























        1












        1








        1







        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 <build> and <plugins> section, just add the <plugin> section below to that. Otherwise you may need to add the whole code below within the <project> element:



         <build>
        <plugins>
        <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
        <archive>
        <manifest>
        <addClasspath>true</addClasspath>
        <mainClass>**REPLACE THIS WITH THE FULL URI OF YOUR MAIN CLASS**</mainClass>
        </manifest>
        </archive>
        <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        </configuration>
        <executions>
        <execution>
        <id>make-my-jar-with-dependencies</id>
        <phase>package</phase>
        <goals>
        <goal>single</goal>
        </goals>
        </execution>
        </executions>
        </plugin>
        </plugins>
        </build>


        2) Make sure that you replace the text in the <mainClass> 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:



        <mainClass>com.example.sub.App</mainClass>


        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.






        share|improve this answer















        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 <build> and <plugins> section, just add the <plugin> section below to that. Otherwise you may need to add the whole code below within the <project> element:



         <build>
        <plugins>
        <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
        <archive>
        <manifest>
        <addClasspath>true</addClasspath>
        <mainClass>**REPLACE THIS WITH THE FULL URI OF YOUR MAIN CLASS**</mainClass>
        </manifest>
        </archive>
        <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        </configuration>
        <executions>
        <execution>
        <id>make-my-jar-with-dependencies</id>
        <phase>package</phase>
        <goals>
        <goal>single</goal>
        </goals>
        </execution>
        </executions>
        </plugin>
        </plugins>
        </build>


        2) Make sure that you replace the text in the <mainClass> 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:



        <mainClass>com.example.sub.App</mainClass>


        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 25 at 4:41

























        answered Mar 25 at 0:30









        kojow7kojow7

        3,49042568




        3,49042568





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321401%2fpdfbox-with-maven-java-lang-noclassdeffounderror%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해