[SOLVED] How to run java in Mageia?

This forum is dedicated to basic help and support :

Ask here your questions about basic installation and usage of Mageia. For example you may post here all your questions about getting Mageia isos and installing it, configuring your printer, using your word processor etc.

Try to ask your questions in the right sub-forum with as much details as you can gather. the more precise the question will be, the more likely you are to get a useful answer

[SOLVED] How to run java in Mageia?

Postby tarazed » May 10th, '16, 20:48

I need to learn about java in order to test various things in QA so have started to look at the web tutorials but so far have not been able to compile the most basic Hello World program. The tutorials mention javac for compilation but that does not seem to exist in Mageia. Browsing turned up gcc-java so I installed that and ran:
Code: Select all
 $ gcc hello.java
no classpath specified


The root of the jre had been added to the PATH environment variable and CLASSPATH had been defined:
Code: Select all
$ setenv  CLASSPATH /home/lcl/qa/java:.

It did not exist before.
Last edited by tarazed on May 11th, '16, 16:41, edited 1 time in total.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49

Re: How to run java in Mageia?

Postby tarazed » May 10th, '16, 20:57

Code: Select all
$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49

Re: How to run java in Mageia?

Postby tarazed » May 11th, '16, 15:52

Extra information:
Edited output from
Code: Select all
$ urpmq -i java-1.8.0-openjdk
URL         : http://openjdk.java.net/

Diagnostics:
Code: Select all
$ which java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/java

$ /sbin/alternatives --display java
java - status is auto.
 link currently points to /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/java - priority 1800091
 slave rmiregistry: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/rmiregistry
 slave pack200.1.xz: /usr/share/man/man1/pack200-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave unpack200: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/unpack200
 slave jjs: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/jjs
 slave servertool.1.xz: /usr/share/man/man1/servertool-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave rmid.1.xz: /usr/share/man/man1/rmid-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave jjs.1.xz: /usr/share/man/man1/jjs-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave keytool.1.xz: /usr/share/man/man1/keytool-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave jre: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre
 slave pack200: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/pack200
 slave rmiregistry.1.xz: /usr/share/man/man1/rmiregistry-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave tnameserv.1.xz: /usr/share/man/man1/tnameserv-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave orbd.1.xz: /usr/share/man/man1/orbd-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave tnameserv: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/tnameserv
 slave policytool: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/policytool
 slave jre_exports: /usr/lib/jvm-exports/jre-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64
 slave servertool: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/servertool
 slave rmid: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/rmid
 slave java.1.xz: /usr/share/man/man1/java-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave unpack200.1.xz: /usr/share/man/man1/unpack200-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
 slave keytool: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/keytool
 slave orbd: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/orbd
 slave policytool.1.xz: /usr/share/man/man1/policytool-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
Current `best' version is /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin/java.


I have seen environment variables JAVA and JAVA_HOME referred to in this forum but none of the online tutorials seem to mention them. I added a couple of elements to my PATH without actually knowing how it should be modified.

Code: Select all
$ path
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/jre/bin
/usr/local/bin
/usr/bin
/usr/local/games
/usr/games
/usr/lib64/qt4/bin
/usr/lib64/qt5/bin
/home/lcl/bin
/usr/lib64/qt5/bin
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/


The Hello World snippet is this:
Code: Select all
public class hellojava {

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

}


and the compiler is gcc.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49

Re: How to run java in Mageia?

Postby tarazed » May 11th, '16, 16:40

Well I never! javac has suddenly appeared. Must be the result of some of those initializations.

javac pointed out the error, and more later:
Code: Select all
$ javac hello.java
hello.java:1: error: class hellojava is public, should be declared in a file named hellojava.java
public class hellojava {
       ^
1 error


Update:
Code: Select all
$ mv hello.java Hello.java
$ cat Hello.java
public class Hello {

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

}
$ javac Hello.java
$ java Hello
Hello World

So practically everything was wrong. Java is strict.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49

Re: How to run java in Mageia?

Postby doktor5000 » May 11th, '16, 19:44

tarazed wrote:Well I never! javac has suddenly appeared. Must be the result of some of those initializations.

I think we might miss something in /etc/profile.d which sets JAVA_HOME or CLASSPATH and that stuff, I think we had that quite some time ago - but I'm not into java, can't help much more.

FWIW, this is how I'd search for javac, if you think it's some binary (in some path with /bin usually):

Code: Select all
[doktor5000@Mageia5]─[19:39:44]─[~] urpmf 'javac$'|grep /bin|sort -u
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-6.b14.1.mga5.i386/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-6.b14.1.mga5.x86_64/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.1.mga5.i386/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.1.mga5.x86_64/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.60-1.b27.1.mga5.i386/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.60-1.b27.1.mga5.x86_64/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-1.b17.1.mga5.i386/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-1.b17.1.mga5.x86_64/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.72-1.b15.1.mga5.i386/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.72-1.b15.1.mga5.x86_64/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.77-1.b03.1.mga5.i386/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.77-1.b03.1.mga5.x86_64/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.i386/bin/javac
java-1.8.0-openjdk-devel:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/bin/javac

and that has to be in your PATH, otherwise you'd have to call it with full path. Maybe you used bash completion, as that exists for javac in /usr/share/bash-completion/completions/javac ... ?
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18058
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: [SOLVED] How to run java in Mageia?

Postby tarazed » May 12th, '16, 00:03

Thanks for the search command. I usually start off by running updatedb then
Code: Select all
 $ locate javac
/etc/alternatives/javac
/etc/alternatives/javac.1.xz
/usr/bin/javac
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64/bin/javac
/usr/lib64/libreoffice/share/config/soffice.cfg/cui/ui/javaclasspathdialog.ui
/usr/share/bash-completion/completions/javac
/usr/share/doc/gettext-devel/examples/build-aux/javacomp.m4
/usr/share/doc/gettext-devel/examples/build-aux/javacomp.sh.in
/usr/share/man/man1/javac-java-1.8.0-openjdk-1.8.0.91-1.b14.1.mga5.x86_64.1.xz
/usr/share/man/man1/javac.1.xz
/usr/share/vim/compiler/javac.vim
/usr/share/vim/syntax/javacc.vim
/var/lib/rpm/alternatives/javac

That is when I saw /usr/bin/javac. At the start there was no such file which is why I tried to resort to gcc.
Can't remember everything that I did. Must have installed something. I think I ran update-alternatives as well. It is all a bit hazy now.
Don't understand about using bash-completion. Need to read up on that. I only ever use completions on the command-line in tcsh and bash.

Have now graduated to trying to import packages. That is yet another story.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49

Re: [SOLVED] How to run java in Mageia?

Postby doktor5000 » May 12th, '16, 18:33

tarazed wrote:Thanks for the search command. I usually start off by running updatedb then
Code: Select all
 $ locate javac

Well, with locate you're limiting yourself to files from packages which are already installed, hence my pointer to urpmf when you're simply searching for a file, no matter if the package containing it is installed or not ;)

tarazed wrote:Have now graduated to trying to import packages. That is yet another story.

If you have questions, consolidate them and just ask in the packaging subforum :)
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18058
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: [SOLVED] How to run java in Mageia?

Postby tarazed » May 12th, '16, 22:52

Sure. I was looking to see if javac had been installed. But, as I said, your search command will certainly come in useful in QA testing. Thanks Florian.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49


Return to Basic support

Who is online

Users browsing this forum: No registered users and 1 guest