• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError  RSS feed

 
Stan Lederer
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • 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?
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 69
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 69
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a section for Maven questions: https://coderanch.com/forums/f-67/tools
 
Stan Lederer
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I've started a new thread there:
Maven tales of woe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!