VectorLinux

Please login or register.

Login with username, password and session length
Advanced search  

News:

Visit our home page for VL info. For support and documentation, visit the Vector Linux Knowledge Center or search the Knowledge Center and this Forum using the search box above.

Author Topic: Compiler for Java?  (Read 1764 times)

Martin109

  • Vectorite
  • ***
  • Posts: 290
Compiler for Java?
« on: June 25, 2011, 01: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
Re: Compiler for Java?
« Reply #1 on: June 25, 2011, 02:00:54 pm »

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

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

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

When I issue the command:

Code: [Select]
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
Re: Compiler for Java?
« Reply #2 on: June 25, 2011, 10: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
Re: Compiler for Java?
« Reply #3 on: June 26, 2011, 06: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: [Select]
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
Re: Compiler for Java?
« Reply #4 on: June 26, 2011, 06:45:57 am »

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

Code: [Select]
./HelloWorld
Logged

Martin109

  • Vectorite
  • ***
  • Posts: 290
Re: Compiler for Java?
« Reply #5 on: June 26, 2011, 02: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