[arch-general] Java Problem
Hello: I have come accross an interesting issue with Java. Let's say I fashion a simple Hello World app, and entitle it hello.java The code would be: class hello { public void main(String[] args) { System.out.println("Hello World!"); } } Then, I compile the code as a regular user, with javac hello.java Here's the odd part: I type java hello, and I get unable to find main class hello But, if I run sudo java bhello, it works fine. What is the solution to not having to run Java software as sudo?
On Sun, Dec 7, 2014 at 7:59 PM, Hunter Jozwiak <hunter.t.joz@gmail.com> wrote:
Hello: I have come accross an interesting issue with Java. Let's say I fashion a simple Hello World app, and entitle it hello.java The code would be: class hello { public void main(String[] args) { System.out.println("Hello World!"); } } Then, I compile the code as a regular user, with javac hello.java Here's the odd part: I type java hello, and I get unable to find main class hello But, if I run sudo java bhello, it works fine. What is the solution to not having to run Java software as sudo?
It is not good Java to have a main() not be public static void main(). If it works when you run sudo(8), then all the better for you, but you really need your class to be `public` as well. Rewrite your code to be: public class hello { public static void main(String[] args) { System.out.println("Hello World!"); } }
On 12/7/14, Toyam Cox <csupercomputergeek@gmail.com> wrote:
On Sun, Dec 7, 2014 at 7:59 PM, Hunter Jozwiak <hunter.t.joz@gmail.com> wrote:
Hello: I have come accross an interesting issue with Java. Let's say I fashion a simple Hello World app, and entitle it hello.java The code would be: class hello { public void main(String[] args) { System.out.println("Hello World!"); } } Then, I compile the code as a regular user, with javac hello.java Here's the odd part: I type java hello, and I get unable to find main class hello But, if I run sudo java bhello, it works fine. What is the solution to not having to run Java software as sudo?
It is not good Java to have a main() not be public static void main(). If it works when you run sudo(8), then all the better for you, but you really need your class to be `public` as well.
Rewrite your code to be:
public class hello { public static void main(String[] args) { System.out.println("Hello World!"); } }
I still have the same issue; I still need to run the code with sudo.
Hi, On 8.12.2014 01:59, Hunter Jozwiak wrote:
Hello: I have come accross an interesting issue with Java. Let's say I fashion a simple Hello World app, and entitle it hello.java The code would be: class hello { public void main(String[] args) { System.out.println("Hello World!"); } } Then, I compile the code as a regular user, with javac hello.java Here's the odd part: I type java hello, and I get unable to find main class hello But, if I run sudo java bhello, it works fine. What is the solution to not having to run Java software as sudo?
Does java -cp . hello work? If so, what is the output of echo $CLASSPATH ? Ondra -- Cheers, Ondřej Kučera
On 12/7/14, Ondřej Kučera <ondrej.kucera@centrum.cz> wrote:
Hi,
On 8.12.2014 01:59, Hunter Jozwiak wrote:
Hello: I have come accross an interesting issue with Java. Let's say I fashion a simple Hello World app, and entitle it hello.java The code would be: class hello { public void main(String[] args) { System.out.println("Hello World!"); } } Then, I compile the code as a regular user, with javac hello.java Here's the odd part: I type java hello, and I get unable to find main class hello But, if I run sudo java bhello, it works fine. What is the solution to not having to run Java software as sudo?
Does java -cp . hello work? If so, what is the output of echo $CLASSPATH ?
Ondra
-- Cheers, Ondřej Kučera The CLASSPATH variable, after java -cp test, says: /home/hjozwiak/GNUstep/libraries/Library/Libraries/Java:/usr/lib/GNUstep/Library/Java
Hi, On 8.12.2014 02:56, Hunter Jozwiak wrote:
On 12/7/14, Ondřej Kučera <ondrej.kucera@centrum.cz> wrote:
Hi,
On 8.12.2014 01:59, Hunter Jozwiak wrote:
Hello: I have come accross an interesting issue with Java. Let's say I fashion a simple Hello World app, and entitle it hello.java The code would be: class hello { public void main(String[] args) { System.out.println("Hello World!"); } } Then, I compile the code as a regular user, with javac hello.java Here's the odd part: I type java hello, and I get unable to find main class hello But, if I run sudo java bhello, it works fine. What is the solution to not having to run Java software as sudo?
Does java -cp . hello work? If so, what is the output of echo $CLASSPATH ?
Ondra
The CLASSPATH variable, after java -cp test, says: /home/hjozwiak/GNUstep/libraries/Library/Libraries/Java:/usr/lib/GNUstep/Library/Java
Well, now the question is why you've set your CLASSPATH to this. You'll probably want to add . (dot) to it as well, e.g. .:/home/hjozwiak/GNUstep/libraries/Library/Libraries/Java:/usr/lib/GNUstep/Library/Java. It depends whether you want the current directory be searched first or not. Ondra -- S pozdravem Ondřej Kučera
participants (3)
-
Hunter Jozwiak
-
Ondřej Kučera
-
Toyam Cox