Click to See Complete Forum and Search --> : javac compiler help. source file canot be read?
JesterDev
05-27-2004, 06:11 PM
I'm just messing around with java a bit to see what it's like. But when I tried to compile my HelloWorldApp I get this error:
error: cannot read: HelloWorldApp.java
1 error
I don't think it's the code.
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display "Hello World!"
}
}
I am running java version:
"1.4.2_03" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
bwkaz
05-27-2004, 06:39 PM
Holy redundant comments Batman! ;)
First thing I'd do is try an ls -l on the HelloWorldApp.java file. Make sure your user has read permission on it...
JesterDev
05-27-2004, 08:12 PM
Well.. Here is the file before a chmod 755:
-rw-r--r-- 1 jester users 361 2004-05-27 04:04 HellowWorldApp.java
And after:
-rwxr-xr-x 1 jester users 361 2004-05-27 04:04 HellowWorldApp.java
Seems I only had read access(?) and now I can execute it.. Or am I reading it wrong? I think I am as I can open it with emacs and edit it.
It's place in a folder in my home directory /home/jester/java_source
bwkaz
05-27-2004, 08:43 PM
You don't need execute permission on it (actually, take that bit OFF, since it can do more harm than good). You need to compile it before it'll be executable -- and even then, you need to execute it with the java bytecode interpreter, not directly from the shell, so you don't need the execute bit set on the class either (though I have seen examples of the binfmt_misc kernel module being used to do stuff like that -- run Java class files, run Windows EXEs using Wine, etc., etc.).
But the compile won't work if the compiler can't read your source file; that was what I thought the issue was. However, you own it (I assume you're doing this as the user jester, right?), and you can also read and write it, so that's not the problem.
How are you compiling it? I can reproduce your error message if I am not in the same directory as the .java file when I do a javac HelloWorldApp.java, but not otherwise...
JesterDev
05-27-2004, 09:03 PM
I am in the same dir as the .java file and I am user jester and I type:
javac HelloWorldApp.java
..
OK, so it works now. I'm not sure what I did other then su and tried to compile like that and got a javac command not found error. But when I exited out of root, and tried it again it worked.
Strange. Either way thank you very much for your help. This is my first attempt at java and I find the syntax quite simular to that of the .NET framework which before I switched to Linux totally I enjoyed very much. So I feel right at home so far. :)
sploo22
05-27-2004, 09:22 PM
I don't know if you were aware of this, but you can use Mono (http://www.go-mono.com/) to compile and run .NET software (to a certain extent, of course) under Linux.