Reputation: 167
I'm trying to run a java file which is in the /lib/jarfile.jar jar file in the path "il/co/codeguru/corewars8086/CoreWarsEngine" with this command in linux:
java -cp lib/jarfile.jar il.co.codeguru.corewars8086.CoreWarsEngine
but I get this error message:
Error: Could not find or load main class il.co.codeguru.corewars8086.CoreWarsEngine
I read I little bit about classpathes in java but i still don't know what is wrong with what I did...
this is the content of CoreWarsEngine
package il.co.codeguru.corewars8086;
import il.co.codeguru.corewars8086.gui.CompetitionWindow;
import java.io.IOException;
public class CoreWarsEngine
{
public static void main (String args[]) throws IOException
{
CompetitionWindow c = new CompetitionWindow();
c.setVisible(true);
c.pack();
}
}
Upvotes: 0
Views: 95
Reputation: 706
Make sure the jar file exists at the location you expect it to be and matches the jar file name in the command. This may seam silly, but java that I have, 11 AdoptOpenJDK does not complain that it did not find the jar file:
java -cp nonexistingfile.jar il.co.codeguru.corewars8086.CoreWarsEngine
Error: Could not find or load main class il.co.codeguru.corewars8086.CoreWarsEngine
Caused by: java.lang.ClassNotFoundException: il.co.codeguru.corewars8086.CoreWarsEngine
Second make sure the jar contains the class you are trying to start. I have stumbled on at least one corewars8086
download on the net that does not have the CoreWarsEngine
class.
If you got the sources from GitHub/codeguru-il/corewars8086 then you need maven to build it. The resulting jar will be in target/corewars8086-4.0.0-SNAPSHOT-jar-with-dependencies.jar
. Or if you build it a different way then you need to figure out where the result jar will be and what is the name.
I managed to run it from the sources of the above repo
Upvotes: 1