• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

NoClassDefFoundError

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sure this question is trivial. I'm learning maven on my Mac. I created a project with a dependency on Apache OpenNLP and it created a jar file. I try running it like this:

I get an error:

I did create a CLASSPATH.

And, that jar does have Tokenizer.class in it.


What am I missing?
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you probably don't want to set the environment variable CLASSPATH.  Using the -cp option on the Java command line overrides it anyway.

Second, you need to be in the directory that contains "my/org/phrases" when you execute this command.  I'm assuming you have a package statement in your code.
 
Master Rancher
Posts: 4465
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the jarfile: BasicNameFinder-1.0-SNAPSHOT.jar  contain the class file: my.org.phrases.BasicNameFinder?
I assume that is true otherwise the java command wouldn't find that class.  If the class was not in the jarfile, the classpath from the -cp would have to refer to the class's path as pointed out in Knute's second point.
If there are other jarfiles that need to be on the classpath, they need to be listed in the -cp option or they could be referenced from the manifest file's Class_Path line.
 
Stan Lederer
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still very confused.

My project directory is <my_home>/src/phrases. That's where pom.xml is.
When I run "mvn clean package" I get a jar file here: <my_home>/src/phrases/target/BasicNameFinder-1.0-SNAPSHOT.jar
The first line of <my_home>/src/main/java/my/org/phrases/BasicNameFinder.java is this:

That same java source has these imports.

And, this fails:

And, BasicNameFinder-1.0-SNAPSHOT.jar has this:
 
Norm Radder
Master Rancher
Posts: 4465
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classpath for the java program needs to have the jarfile for your program's classes and the jarfile for the Tokenizer class.  I don't know what the path separator is for a Mac.  
On Windows the command would be like this with a ; separating the paths:
java -cp BasicNameFinder-1.0-SNAPSHOT.jar;opennlp-tools-1.6.0.jar      org.my.phrases.BasicNameFinder

I left off the full path and just used the jarfile to simply the command.

 
Stan Lederer
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much. I got further with this:

java -cp BasicNameFinder-1.0-SNAPSHOT.jar:<my_home>/apache-opennlp-1.6.0-src/apache-opennlp-1.6.0-src/opennlp-tools/target/opennlp-tools-1.6.0.jar gov.osti.phrases.BasicNameFinder

The new error is this:


I think it's time for me to start a new thread if questions about Maven are appropriate on this forum. I've got my java source, the OpenNLP jars, and now the slf4j stuff. I've added dependencies on slf4j-api and on opennlp-tools in the pom.xml but Maven isn't doing anything with them as far as I can tell. That's why I'm referencing the opennlp jars in the first place, which I built as a different Maven project.

 
Norm Radder
Master Rancher
Posts: 4465
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a section for Maven questions: https://coderanch.com/forums/f-67/tools
 
Stan Lederer
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I've started a new thread there:
Maven tales of woe
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic