Compiling and running java source code from the terminal??

Hi, I’m struggling to compiile my java source code and run it from the terminal… (Yeah I’m new to OpenSUSE/linux in general)

I’ve made a simple program which I then try to compile using “javac Welcome.java” and I get…

green@linux-v85t:~> cd Desktop
green@linux-v85t:~/Desktop> cd Java
green@linux-v85t:~/Desktop/Java> ls
test.java Welcome.java
green@linux-v85t:~/Desktop/Java> javac Welcome.java
If ‘javac’ is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf javac
green@linux-v85t:~/Desktop/Java>

Now on Windows I remember I had to do something with the environment variables but I have no idea how to do that here.

java -version gives me…

java version “1.7.0_15”
OpenJDK Runtime Environment (IcedTea7 2.3.7) (suse-8.3.1-i386)
OpenJDK Server VM (build 23.7-b01, mixed mode)

Any help is much appreciated.

Thanks

Also, how would I go about updating my java version?

if i am correct you only have JRE and no JDK(development kit) on you machine
to install JDK run the following command in terminal / konsole

sudo zypper in '*openjdk*devel*'

After installing you can use javac or java compiler.

When you need to update your software packages including java you need to run the following command in terminal/konsole

sudo zypper ref -f
sudo zypper up

Special Note:- ensure that you have correct repos on your machine

Thank you for the replies, being new to linux I’m not sure what a “repo” is could you link me to a source that explains it well?

:slight_smile:

Post output of the below command(you can select and copy output from terminal using ctrl+shift+c and paste here using ctrl+v) within code tags(use # button in post editor)

zypper lr -d

After reading the below stuff you should do this Post#2

Package Management and repository
Ultra Random Thoughts: Understanding “Package Management” in Linux
openSUSE 12.3: Chapter 5. Installing or Removing Software
https://en.opensuse.org/SDB:Zypper_usage

More reads
Official - you need Oss , Non-oss,Update ,Update non-oss
https://en.opensuse.org/Package_repositories
Additional:- you need packman for video and audio codecs
https://en.opensuse.org/Additional_package_repositories

On 2013-07-05 18:16, thegreenmarine wrote:
>
> Hi, I’m struggling to compiile my java source code and run it from the
> terminal… (Yeah I’m new to OpenSUSE/linux in general)
>
> I’ve made a simple program which I then try to compile using “javac
> Welcome.java” and I get…

Trick.
For posting code in the forums, you have to paste it inside a…, guess,
CODE block :wink:

It is the ‘#’ button in the advanced editor.


> green@linux-v85t:~> cd Desktop
> green@linux-v85t:~/Desktop> cd Java
> green@linux-v85t:~/Desktop/Java> ls
> test.java  Welcome.java
> green@linux-v85t:~/Desktop/Java> javac Welcome.java
> If 'javac' is not a typo you can use command-not-found to lookup the
> package that contains it, like this:
> cnf javac
> green@linux-v85t:~/Desktop/Java>

Now on Windows I remember I had to do something with the environment
variables but I have no idea how to do that here.

The text above is telling you what is the problem and what to do. javac
is not found, and the usual reason is because you typed it wrong, and if
it is correctly typed then because it is not installed. And it proposes
you type “cnf javac” to find out if you can install it.

Why did you not try?


cer@Telcontar:~> cnf javac
javac: command not found
cer@Telcontar:~>

Well, in this case it is not very helpful :-}

But you have already been told what you need.

> Also, how would I go about updating my java version?

Just by running “yast online update” should do it.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

> Also, how would I go about updating my java version?

Just by running “yast online update” should do it.

You can invoke (cq start) Yast Online Update by typing “you” in your konsole. Without the quotes ofcourse :slight_smile: