VectorLinux
November 27, 2014, 01:38:49 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: Compiler for Java?  (Read 1617 times)
Martin109
Vectorite
***
Posts: 290


« on: June 25, 2011, 12:39:04 pm »

I can compile and run C programs with gcc, but what about java?

I have installed gcc-java 4.2.3-i486-1 but the command gcc-java doesn't do anything.

What do I need to do next to get java running?
Logged

Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard
Martin109
Vectorite
***
Posts: 290


« Reply #1 on: June 25, 2011, 01:00:54 pm »

OK, it's part of gcc, evoked with gcj!

Here's the classic "Hello, World!" program in java:

Code:
class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World.");
}
}

When I issue the command:

Code:
gcj [path-to]HelloWorld.java

I get:

/usr/lib/gcc/i486-slackware-linux/4.2.3/../../../crt1.o: In function '_start':
(.text+0x18): undefined reference to 'main'
collect2: ld returned 1 exit status

Anyone know what's going wrong?
      
Logged

Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard
DavidI
Member
*
Posts: 9


« Reply #2 on: June 25, 2011, 09:57:09 pm »

I don't use gcj anymore but when I did I had to specify the main method:

gcj --main=HelloWorld -o HelloWorld HelloWorld.java
Logged
Martin109
Vectorite
***
Posts: 290


« Reply #3 on: June 26, 2011, 05:02:07 am »

I don't use gcj anymore but when I did I had to specify the main method:

gcj --main=HelloWorld -o HelloWorld HelloWorld.java

OK, when I issue that command the system produces another file  - HelloWorld*

When I issue the command 'java HelloWorld', I get:

Code:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native method)
at java.et.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: HelloWorld.  Program will exit.


Logged

Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard
DavidI
Member
*
Posts: 9


« Reply #4 on: June 26, 2011, 05:45:57 am »

The file isn't bytecode so it isn't run by the JVM. Just use:

Code:
./HelloWorld
Logged
Martin109
Vectorite
***
Posts: 290


« Reply #5 on: June 26, 2011, 01:10:24 pm »

Thanks, David, that's helped a lot!
Logged

Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!