Page 1 of 1

Installing and Setting up Java

Posted: Sun Jul 08, 2007 4:52 pm
by lamdacore
Hi,

I am facing problems in setting the classpath to invoke javac to run java programs. Please provide a solution to easily solve many of my problems.

Anyhow, to simplify the problem, I did some homework on my own and managed to set some variables in /etc/environment as:

$CLASSPATH = /etc/java/jdk1.6.0_01/lib:.
$JAVA_HOME = /etc/java/jdk1.6.0_01/
$PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games

Now the main problem is that i cannot call 'java' or 'javac' at the terminal. However, when i get to the folder: cd $JAVA_HOME/bin/

and type './java' or './javac' only then do these executables work.

what i want is that i would like both of these executables to run from anywhere in filesystem directory when in the terminal. Because of this problem many IDEs will not compile any Java program.

Please help

Thanks

Lamdacore

Posted: Sun Jul 08, 2007 5:57 pm
by scorp123

Code: Select all

sudo apt-get install sun-java6-bin sun-java6-fonts sun-java6-jre sun-java6-plugin sun-java6-jdk
And for the rest: I don't know what you did there. All the binaries are working tip top for me from anywhere. You should check your $PATH variables and /etc/alternatives ... Mine look like this:

Code: Select all

lrwxrwxrwx   1 root root    31 2007-07-09 00:03 jar -> /usr/lib/jvm/java-6-sun/bin/jar
lrwxrwxrwx   1 root root    41 2007-07-09 00:03 jar.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jar.1.gz
lrwxrwxrwx   1 root root    37 2007-07-09 00:03 jarsigner -> /usr/lib/jvm/java-6-sun/bin/jarsigner
lrwxrwxrwx   1 root root    47 2007-07-09 00:03 jarsigner.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jarsigner.1.gz
lrwxrwxrwx   1 root root    36 2007-06-23 02:08 java -> /usr/lib/jvm/java-6-sun/jre/bin/java
lrwxrwxrwx   1 root root    46 2007-06-23 02:08 java.1.gz -> /usr/lib/jvm/java-6-sun/jre/man/man1/java.1.gz
lrwxrwxrwx   1 root root    33 2007-07-09 00:03 javac -> /usr/lib/jvm/java-6-sun/bin/javac
lrwxrwxrwx   1 root root    43 2007-07-09 00:03 javac.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javac.1.gz
lrwxrwxrwx   1 root root    35 2007-07-09 00:03 javadoc -> /usr/lib/jvm/java-6-sun/bin/javadoc
lrwxrwxrwx   1 root root    45 2007-07-09 00:03 javadoc.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javadoc.1.gz
lrwxrwxrwx   1 root root    33 2007-07-09 00:03 javah -> /usr/lib/jvm/java-6-sun/bin/javah
lrwxrwxrwx   1 root root    43 2007-07-09 00:03 javah.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javah.1.gz
lrwxrwxrwx   1 root root    33 2007-07-09 00:03 javap -> /usr/lib/jvm/java-6-sun/bin/javap
lrwxrwxrwx   1 root root    43 2007-07-09 00:03 javap.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javap.1.gz
lrwxrwxrwx   1 root root    40 2007-07-09 00:03 java-rmi.cgi -> /usr/lib/jvm/java-6-sun/bin/java-rmi.cgi
lrwxrwxrwx   1 root root    39 2007-06-23 02:08 java_vm -> /usr/lib/jvm/java-6-sun/jre/bin/java_vm
lrwxrwxrwx   1 root root    38 2007-06-23 02:08 javaws -> /usr/lib/jvm/java-6-sun/jre/bin/javaws
lrwxrwxrwx   1 root root    48 2007-06-23 02:08 javaws.1.gz -> /usr/lib/jvm/java-6-sun/jre/man/man1/javaws.1.gz
lrwxrwxrwx   1 root root    36 2007-07-09 00:03 jconsole -> /usr/lib/jvm/java-6-sun/bin/jconsole
lrwxrwxrwx   1 root root    46 2007-07-09 00:03 jconsole.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jconsole.1.gz
lrwxrwxrwx   1 root root    40 2007-06-23 02:08 jcontrol -> /usr/lib/jvm/java-6-sun/jre/bin/jcontrol
lrwxrwxrwx   1 root root    31 2007-07-09 00:03 jdb -> /usr/lib/jvm/java-6-sun/bin/jdb
lrwxrwxrwx   1 root root    41 2007-07-09 00:03 jdb.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jdb.1.gz
lrwxrwxrwx   1 root root    32 2007-07-09 00:03 jhat -> /usr/lib/jvm/java-6-sun/bin/jhat
lrwxrwxrwx   1 root root    42 2007-07-09 00:03 jhat.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jhat.1.gz
lrwxrwxrwx   1 root root    33 2007-07-09 00:03 jinfo -> /usr/lib/jvm/java-6-sun/bin/jinfo
lrwxrwxrwx   1 root root    43 2007-07-09 00:03 jinfo.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jinfo.1.gz
lrwxrwxrwx   1 root root    32 2007-07-09 00:03 jmap -> /usr/lib/jvm/java-6-sun/bin/jmap
lrwxrwxrwx   1 root root    42 2007-07-09 00:03 jmap.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jmap.1.gz
lrwxrwxrwx   1 root root    31 2007-07-09 00:03 jps -> /usr/lib/jvm/java-6-sun/bin/jps
lrwxrwxrwx   1 root root    41 2007-07-09 00:03 jps.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jps.1.gz
lrwxrwxrwx   1 root root    38 2007-07-09 00:03 jrunscript -> /usr/lib/jvm/java-6-sun/bin/jrunscript
lrwxrwxrwx   1 root root    48 2007-07-09 00:03 jrunscript.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jrunscript.1.gz
lrwxrwxrwx   1 root root    37 2007-07-09 00:03 jsadebugd -> /usr/lib/jvm/java-6-sun/bin/jsadebugd
lrwxrwxrwx   1 root root    47 2007-07-09 00:03 jsadebugd.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jsadebugd.1.gz
lrwxrwxrwx   1 root root    34 2007-07-09 00:03 jstack -> /usr/lib/jvm/java-6-sun/bin/jstack
lrwxrwxrwx   1 root root    44 2007-07-09 00:03 jstack.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jstack.1.gz
lrwxrwxrwx   1 root root    33 2007-07-09 00:03 jstat -> /usr/lib/jvm/java-6-sun/bin/jstat
lrwxrwxrwx   1 root root    43 2007-07-09 00:03 jstat.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jstat.1.gz
lrwxrwxrwx   1 root root    34 2007-07-09 00:03 jstatd -> /usr/lib/jvm/java-6-sun/bin/jstatd
lrwxrwxrwx   1 root root    44 2007-07-09 00:03 jstatd.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/jstatd.1.gz
lrwxrwxrwx   1 root root    39 2007-06-23 02:08 keytool -> /usr/lib/jvm/java-6-sun/jre/bin/keytool


Posted: Tue Jul 10, 2007 6:05 am
by lamdacore
thanks scorp123 for your reply and i looked into what you suggested. However, i manged to fix my $PATH and now i can invoke 'javac' to compile java programs. However, when i try to execute the *.class file by invoking the 'java' command, I get the following error:
==============================================

Exception in thread "main" java.lang.ClassFormatError: <filename> (unrecognized class file version)
at java.lang.VMClassLoader.defineClass(libgcj.so.70)
at java.lang.ClassLoader.defineClass(libgcj.so.70)
at java.security.SecureClassLoader.defineClass(libgcj.so.70)
at java.net.URLClassLoader.findClass(libgcj.so.70)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.70)
at java.lang.ClassLoader.loadClass(libgcj.so.70)
at java.lang.ClassLoader.loadClass(libgcj.so.70)
at gnu.java.lang.MainThread.run(libgcj.so.70)

==============================================

I believe that the problem exists because the JRE installed is an older version and therefore cannot execute the bytecode created by the java compiler. Can someone please tell me how to fix this error. I mean what paths and variables do i have to set and how to set these vaiables i.e. to uninstall the old JRE so that the new one can take over and resolve the problem.

thanks

Lamdacore

Posted: Sun Jul 15, 2007 4:22 pm
by scorp123
kainnvin wrote:It's probably best to uninstall everything and install using the installers sun has in their website.
And why would that be "the best"?? Please explain!

Posted: Wed Jul 18, 2007 9:51 am
by scorp123
kainnvin wrote: Because the Sun installer is easy to use, and it configures everything.
Maybe ... but then this also means that your JDK installation is outside of the "apt" repos which can create new problems. I personally prefer to use the repos.
kainnvin wrote: I just downloaded NetBeans+JDK, and no more worries.
You could post this in the "How to" section as an alternative to installing Java via the repos.
kainnvin wrote: Oh, btw, javac isnt installed to a path directory nor its directory is added to path,
Not true in my case :-) ... and I installed it via the repos. And it's there in my $PATH.

Posted: Sun Aug 19, 2007 5:53 pm
by yuri21
Edit: Man, it looks like common sense departed me the previous day. :o How could I forget about aptitude?

Does anyone know how to "force" Linux to uninstall certain software only without uninstalling everything else?

Thats 'cos Linux keeps telling me this whenever I try to uninstall java-6-bin.

The following packages will be REMOVED:
bsh libhsqldb-java libjaxp1.3-java libjline-java libservlet2.3-java
libxalan2-java libxerces2-java openoffice.org openoffice.org-base
openoffice.org-filter-mobiledev openoffice.org-java-common sun-java6-bin
sun-java6-fonts sun-java6-jdk sun-java6-jre sun-java6-plugin
0 upgraded, 0 newly installed, 16 to remove and 0 not upgraded.

Posted: Mon Aug 20, 2007 3:43 am
by yuri21
Okay, I give up. Java refuses to work on my computer on either Swiftfox and Opera. I have NoScript on Swiftfox set to allow Java.

Whenever I go to a site with Java, I will get the "Additional plugins are required to display all the media on this page."

In two separate attempts, I tried reinstalling sun-java6-bin and later on, j2re1.4.

Is this an issue of broken symbiolic links?

Edit: ran Opera and tried to access some site with java. The java loaded and then crashed. Here's the log: http://pastebin.com/f1ee64ea4