Search code examples
javaeclipseconfigurationlauncher

How to launch java application without having to specify classpath?


I'm new to java and I'm experimenting with hello world app. I've exported the app from Eclipse into a jar, i DID specify the launch configuration, and when I ran it from command line, I retrieved

Error: Could not find or load main class

That can be fixed by specifying class path like this:

java -cp .:myjar.jar MyMainClass

However, this is really inconvenient. Is there any way, preferably through eclipse, to specify MyMainClass as a metadata inside the jar file so I don't have to write it down every time I launch the app?


Solution

  • yes, you can by writing a manifest file, and then running java -jar Yourjarfile.jar