-1

I have a few java classes that do a simple data base test. I have all of the java files in a folder called "MorphiaTest". I also have all of the jars they depend on in that exact same folder. I want to compile this little application so I can move it around and run it.

I'm running ubuntu and trying to do this all from the command line so I can SCP my compiled app onto a server.

In this one folder is QueryTest.java and Record.java as well as the requisite Mongo-java-driver.jar and morphia-1.3.2.jar.

All I want to do is compile these and run "java QueryTest" from the command line and have my program run.

This is how I'm compiling

javac -cp ":mongo-java-driver-3.8.2.jar:morphia-1.3.2.jar" QueryTest.java Record.java 

All fine and dandy this compiles fine. But when I go to run "java QueryTest" I get this:

Error: Unable to initialize main class QueryTest
Caused by: java.lang.NoClassDefFoundError: org/mongodb/morphia/Datastore

What am I doing wrong?

macmeyers50
  • 309
  • 2
  • 15
  • 1
    You need to specify the `-cp` again when running. The classpath used for compilation is not saved. – Andreas Feb 17 '21 at 22:50

1 Answers1

0

Got it working.

To Compile: javac -cp .:mongo-java-driver-3.8.2.jar:morphia-1.3.2.jar QueryTest.java Record.java

To Run: java -cp .:mongo-java-driver-3.8.2.jar:morphia-1.3.2.jar QueryTest

macmeyers50
  • 309
  • 2
  • 15