• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

getting NoClassDefFoundError Jsoup with Maven

 
Ranch Hand
Posts: 49
1
Firefox Browser VI Editor Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there
I'm trying Jsoup and Maven by following the Jsoup handbook but have issues running the code.
So I created a project using maven and added Jsoup as a dependency, this is the POM:

and this is my only java file:

and tried creating an excutable jar file using both and then running the jar file via but I get this exception:

I would appreciate any help
 
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java expects you to put all your dependencies on the class path. The only JAR you have on your classpath is your exbook JAR.

There are 4 ways you can solve this problem:

  • Add JSoup to the class path when you call the java command.
  • Add JSoup to your JAR's Class-Path manifest entry.
  • Use exec-maven-plugin to run your application.
  • Create a "fat JAR" that includes both JSoup and your own classes.

  • Using exec-maven-plugin would be my personal preference, but your POM already contains a start for creating a fat JAR. All you need to do is finish configuring maven-assembly-plugin and then add it to the list of plugins to execute when you're building your application.
     
    Nadiyar Mansouri
    Ranch Hand
    Posts: 49
    1
    Firefox Browser VI Editor Fedora
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for reply Stephan van Hulst
    I was able to run the program using exec-maven-plugin fine but I can't generate a fat jar.
    So I updated these attributes of POM:

    And tried making jar file by running mvn package however the jar-with-dependencies is not made and I get a normal JAR which returns following error after excuting



    Not a “Beginning” topic: moved to our Maven forum.


    ok Campbell Ritchie thanks for notifying.
     
    Come have lunch with me Arthur. Adventure will follow. This tiny ad:
    Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
    https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic