1

I have a working Java program that I have moved from the default package into another defined package. It seems that the compiler cannot find the main class now, I am not sure how to proceed from here.

When using packages do I need to somehow set the class path so that the main method can be found? I have read up on some tutorials on packages but none seem to be point me in the right direction.

user3728545
  • 71
  • 1
  • 1
  • 5
  • You can always put a Main class in the default package and keep the rest of your code in other packages. – Pokechu22 Sep 15 '14 at 16:55
  • 1
    You have to define a `Main-Class:` in your MANIFEST.MF file. – Peter Lawrey Sep 15 '14 at 16:55
  • 1
    The key here is to look at and fully understand your jar file's Manifest file which is where you tell Java where to find the start-up class. For details on how to use this, please look here: [Manifest File, the Basics](http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html). – Hovercraft Full Of Eels Sep 15 '14 at 16:55
  • If you want to be able to run different main methods from time to time using the terminal: java -cp jarfile.jar package.classnamewithmainmethod –  Sep 15 '14 at 16:59

0 Answers0