LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   get java working in Ubuntu 18.04 (https://www.linuxquestions.org/questions/linux-software-2/get-java-working-in-ubuntu-18-04-a-4175643918/)

Pedroski 12-08-2018 09:01 PM

get java working in Ubuntu 18.04
 
I want to try to learn some java. I am reading here.

I have java installed, I know because I use a java program Formreturn, which works well.

Quote:

pedro@pedro-school2:~/myJava$ sudo update-alternatives --config java
[sudo] password for pedro:
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
* 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

Press <enter> to keep the current choice[*], or type selection number:
I read that I need to set the PATH, so I did this:

Quote:

pedro@pedro-school2:~/myJava$ echo $PATH
/home/pedro/bin:/home/pedro/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
pedro@pedro-school2:~/myJava$ export PATH=$PATH:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
pedro@pedro-school2:~/myJava$ echo $PATH
/home/pedro/bin:/home/pedro/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
pedro@pedro-school2:~/myJava$
Trouble with $PATH: on reboot, the PATH to java was gone again.

I thought I would use Geany as my editor. When I try to run helloWorld.java from Geany, I get this error:

Quote:

Error: Could not find or load main class helloWorld


------------------
(program exited with code: 1)
Press return to continue
Which is the same as I get in a Bash shell:

Quote:

pedro@pedro-school2:~/myJava$ java ./helloWorld.java
Error: Could not find or load main class ..helloWorld.java
pedro@pedro-school2:~/myJava$
I am in the directory where helloWorld.java is.

What have I got to do to make it run? How do I make the PATH stick??

AwesomeMachine 12-08-2018 11:32 PM

You can edit .bashrc and change the path there. Then, source .bashrc to make the change. After that the path should survive reboots.

Also, read this page: https://docs.oracle.com/javase/tutor...ion/index.html

Pedroski 12-09-2018 07:09 PM

Thanks. Did what you said. Got it working.

javac, which I presume is java compiler, creates helloWorld.class in my java folder, After that, it runs OK with just java helloWorld.

Actually, it's the girlfriend who wants to learn some java. Somehow I think I am in for quite a few headaches! I'm happy with my little Python routines!


All times are GMT -5. The time now is 06:38 PM.