2

I have a file 'Junit.class' and I run it from command line like normal (java Junit). In eclipse I run it and the imported statements work, getting them from the .jar files I have. when I run it from the command line it wont run. Eclipse made the Junit.class file and I do

:~java Junit

Errors come from it not being able to find the imported classes.Do I need to include the jar file and if so how, for example is there a way to do ?

:~ java (jar_File_1) (Jar_file_2) Junit.class

Basically I just need the jar files for the imported classes in my Junit class.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
Mikecit22
  • 157
  • 1
  • 14
  • When you mean running the Junit class, you mean running the tests and not a `main` method, right? – Luiggi Mendoza Mar 04 '14 at 14:58
  • possible duplicate of [How to run JUnit test cases from the command line](http://stackoverflow.com/questions/2235276/how-to-run-junit-test-cases-from-the-command-line) – Luiggi Mendoza Mar 04 '14 at 15:27

1 Answers1

5

You need to set the classpath to reference the relevant .jar files and directories e.g.

$ java -cp jarfile1.jar;jarfile2.jar;/home/user/classes mypackage.MyClass

Note the ; separator is for Windows, and you should use : for Unix. Note also that you specify the classname without the .class suffix.

Check out the official Oracle documentation for more info on this often confusing subject.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440