Ask Your Question
0

java won't run

asked 2016-03-06 23:14:56 -0500

updated 2016-03-07 05:08:51 -0500

hhlp gravatar image

Hi,

I'm new to using Fedora 23 and I'm trying to compile and run Java programs. My problem is that the program will not run, it compiles fine but when I try to run it I get an error message which says "Could not find or load main class .home.myname.Documents.Ex1_1". The commands I use to compile and run are (after entering root access):

javac /home/myname/Documents/Ex1_1.java
java /home/myname/Documents/Ex1_1
and Ex1_1.class

I've verified that openJDK is up-to-date.

Thanks

edit retag flag offensive close merge delete

Comments

Thank you, that worked. I tried using root as a last resort. Is there any reason why it wouldn't work without changing the directory like I had?

tenteisei1 gravatar imagetenteisei1 ( 2016-03-07 09:33:25 -0500 )edit

Try running it as root.

RealPlayerCraft gravatar imageRealPlayerCraft ( 2016-03-07 10:54:12 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-03-07 05:49:38 -0500

mithrial gravatar image

updated 2016-03-07 13:47:08 -0500

Why would you run it as root? Don't do that.

The java-runtime tries to load the class Ex1_1 in the package home.myname.Documents. To properly run it, change directory into Documents and do it from there. cd /home/myname/Documents, then

javac Ex1_1.java to compile and

java Ex1_1 to run

Or you can give the classpath to the Runtime with the -cp parameter:

javac /home/username/documents/Ex1_1.java
java -cp /home/username/documents Ex1_1

Note the space in the last line between the path where the class is, and the class which is to run.

edit flag offensive delete link more
0

answered 2016-03-07 11:44:10 -0500

fcomida gravatar image

Nothing to do with Fedora.

java -cp /home/myname/Documents Ex1_1

'java -h' or, better, a beginner intro to java programming

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-06 23:14:56 -0500

Seen: 181 times

Last updated: Mar 07 '16