Getting Started with Java on Linux

Installing and testing JDK and Resin to set up your own Java application server.
Summary

This little tutorial has gotten you started with your Java adventure on Linux. Using Resin as your web and application server gives you all the possibilities that the not-so-cheap alternatives do, including XML/XSL processing, JSP/Servlet support and load balancing. If you choose Resin-EE, you also receive EJB (Enterprise Java Beans). For a detailed description of what you are allowed to do with Resin, read the Caucho Developer Source License. It comes with your Resin installation, in /usr/local/resin/LICENSE.

Resin also offers almost endless tweaking possibilities, which can be used to configure the functions of your server and also to improve performance in some setups. The complete Resin configuration reference can be found at www.caucho.com/resin/ref/config.xtp.

If you have no plans to use Java for web development, you still have a working Java development environment for standalone applications. A good starting point for all Java programming is java.sun.com/docs. There you'll find the complete standard API reference, as well as documentation on other interesting Java technologies, including APIs for programming 3D, SSL, Speech and others.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Getting Started with Java on Linux

Anonymous's picture

i am getting such result after typing javac at home directory
kindly , give me some solution for the problem
[jdk1_3_1_12 is stored in /usr/local]

/usr/local/jdk1.3.1_12/bin/i386/native_threads/javac: error while loading shared libraries: libstdc++-libc6.1-1.so.2: cannot open shared objectfile: No such file or directory
[root@localhost home]#

may be you should store at

praveen's picture

may be you should store at ./usr/local/jdk

I think you don't have file l

Lukaash's picture

I think you don't have file libstdc....... Try to find some .rpm that contains that file. I had the same problem, but I don't remember name of the .rpm.

Re: Getting Started with Java on Linux

Anonymous's picture

I really Donot know about this! sorry

Re: Getting Started with Java on Linux

Anonymous's picture

me too....somebody please help..

Re: Getting Started with Java on Linux

Anonymous's picture

This document has two parts. The first explains how to install just the Java software development kit. The second part explains how to install the Sun One Studio (previously known as Forte). This is how it worked for me. Any risk in using this information is yours (don't whine to me, I ain't got no money anyway).

How to install Java JDK:

1. Decide on a directory to hold the jdk folder (I used /usr/local) and change to it using:

linux:~# cd /usr/local

2. Download the "j2sdk-1_4_1_01-linux-i586.bin" from ww.java.sun.com into the current directory.

3. Change the permisions on the file using:

linux:/usr/local# chmod 755 j2sdk-1_4_1_01-linux-i586.bin

4. Run the binary:

linux:/usr/local# j2sdk-1_4_1_01-linux-i586.bin

. This will create a new subdirectory, j2sdk-1_4_1_01, and install the sdk into it after you have scrolled through the license agreement and answered "yes" to "Do you agree to the above license terms? [yes or no]"

5. Enter:

linux:/usr/local# ln -s /usr/local/j2sdk-1_4_1_01 /usr/local/jdk

This creates a symbolic link, /usr/local/jdk, to the j2sdk-1_4_1_01 directory. This way you can have the jdk directory in the path, and upgrade your versions merely by installing it to its own directory and then changing the symbolic link again.

6. Append to /etc/profile:

export PATH=$PATH:/usr/local/jdk/bin

to make sure the /usr/local/jkd/bin directory (but really the

/usr/local/j2sdk-1_4_1_01/bin directory ) is in your path.

7. Reload the /etc/profile by:

linux:~# source /etc/profile

8. Enter

linux:~# javac

to check that it is properly installed.

9. Append to /etc/profile:

export JAVA_HOME=/usr/local/jdk

to tell your system where the JDK base directory can be found.

How To Install Sun One Studio:

1. Download the "j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin" file. Make sure downloaded file is the same size as indicated on the Sun web page.

2. To change permisions run:

linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin

3. Decide on a directory( eg. /usr/local).

4. Run:

linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin

The installer will start up, ask if you agree to the license terms, and if you say yes, it will ask which directory to install to (I chose /usr/local/s1studio4_1_1). There is no need to be currently in that particluar directory at the time. It will create a new directory tree in /usr/local/s1studio4_1_1 with subdirectories _uninst, j2sdk1.4.1, and s1studio.

5. The installer will put focus on the finish button when it's done. When you press it, a small message box comes up saying that to start the program, you must run runide.sh in /~/s1studio/bin to start the IDE.

6. If you HAVE NOT previously installed the jdk then append to '/etc/profile':

export PATH=$PATH:/usr/local/s1studio4_1_1/j2sdk1.4.1/bin

If you HAVE previously installed the jdk but want to use the new one, then edit '/etc/profile' to remove the export PATH line that contains your old jdk or j2sdk directory and append the new export PATH command to the profile file.

7. Append the next line to /etc/profile:

export PATH=$PATH:/usr/local/s1studio4_1_1/s1studio/bin

Save profile and exit the editor.

8. Reload the /etc/profile by:

linux:~# source /etc/profile

9. The only way I figured the following out, was by reading the runide.sh file. I found no documentation, no hint or clue elsewhere.

To start the IDE, runide.sh needs to know where the jdk is. The installation leaves it no clue, so you have to pass it a command line argument as shown:

runide.sh -jdkhome /usr/local/jdk

or

runide.sh -jdkhome /usr/local/s1studio4_1_1/j2sdk1.4.1

depending on your choice in part 6.

10. The easiest way I found to get the ide to start was to right-click the mouse on the KDE panel, then click on Add in the menu that pops up. On the next sub-menu click on SpecialButton, and next on Non-KDE Application. This will bring up a file selection box. Browse until you find the runide.sh file, and click on it. This will come up with a Non-KDE Application Configuration data-entry box. In the edit field, enter: -jdkhome /usr/local/jdk. You can click on the icon now to change it, or you can change it at any later time by simply right-clicking the icon on the panel to edit the preferences.

At this point I had an icon on the panel which I could left-click on to start the IDE.

Ron Gesell

Jan 28, 2003

Re: Getting Started with Java on Linux

Anonymous's picture

sorry.. just want to ask how to run java applet(yahoo chess applet) on linux(rh9)

i had already install j2sdk1.4.1.02
i follow all the step above(i manage to compile java prog)... but still can open yahoo chess applet...
what else should i install

or should i install j2re?

just begin to know linux..

I think there is an error

Anonymous's picture

I think there maybe an error in the tute. Although I am a beginner, so maybe I'm mistaken

towards the top there is the command :

mv j2sdk-1_4_0_01-linux-i586.bin /usr/local

I think that this is wrong and in fact should be

mv j2sdk-1_4_0_01 /usr/local

What the point in moving the .bin ?

please correct me If Im wrong but beginners like me try to follow the commands exactly and this is confusing

2cj2

Re: I think there is an error

Anonymous's picture

Yes Its me again

I believe that I was correct before. Also I need to know how to set the path name when Im not in root. These couple of points would I feel be of great benefit in what is a great tutorial !

2cj2

Not The Error!!!!!!!

DSagar's picture

Hey dude.. its not Error as we have to move .bin file to /usr/local directory... Its the name of that package for Linux so its same if write jdk_1_4_0 or jdk_...bin ok by by... Correct me if I'm wrong anyway...

Re: Getting Started with Java on Linux

Anonymous's picture

Nice Java Intro.

But -- Resin is not an application server, Resin is a servlet-engine. And -- Linux being open source and all, why not choose an open source appserver for the example? JBoss or Jonas anyone?

Re: Getting Started with Java on Linux

Anonymous's picture

Why use reflection to get the length of an array?

Every array instance has a member .length ....

Re: Getting Started with Java on Linux

Anonymous's picture

yeah, funny. maybe he likes reflecting

this works just as well....

class Test

{

public static void main( String argv[] )

{

System.out.println( "Arguments:" );

int i = 0;

while( i < argv.length )

{

System.out.println( argv[i] );

i++;

}

}

}

Re: Getting Started with Java on Linux

solle's picture

Haha.... Yeah, well, I'm a little mystery, I guess :)

Getting started with Tomcat instead of Resin

Anonymous's picture

Just in case someone wants to try out Tomcat instead of Resin, here is a quick&dirty summary:

Download Tomcat binary from jakarta.apache.org

Unpack the binary (I unpack mine in /usr/local

Start tomcat by running /usr/local/jakarta-tomcat-4.0.4/bin/startup.sh

You may need to set the JAVA_HOME environment variable to point to your Java directory before Tomcat will start.

By default, Tomcat starts on port 8080. If you want to change it, edit the server.xml file in /usr/local/jakarta-tomcat-4.0.4/conf. (Just search for port="8080")

When you create the test JSP, put it in /usr/local/jakarta-tomcat/webapps/ROOT.

The URL should be http://localhost:8080/test.jsp?par=mysecretvalue

The Tomcat installation comes with documentation, just point your browser to http://localhost:8080 and you should get the main page for your installation, with links to the docs. If you have JDK 1.4, it is easy to enable SSL with Tomcat as well.

Re: Getting started with Tomcat instead of Resin

Anonymous's picture

Currently I've got tomcat running on port 8080, but would like to be able to run it with apache on port 80. So, has anyone able to get it to work with apache? If so what kind of connector did you use and what are the steps?

Re: Getting Started with Java on Linux

Anonymous's picture

Why use Resin ? Jakarta Tomcat is mature, free, and FREE product.

nedim

Re: Getting Started with Java on Linux

Anonymous's picture

This document has two parts. The first explains how to install just the Java software development kit. The second part explains how to install the Sun One Studio (previously known as Forte). This is how it worked for me. Any risk in using this information is yours (don't whine to me, I ain't got no money anyway).

How to install Java JDK:

1. Decide on a directory to hold the jdk folder (I used /usr/local) and change

to it using:

linux:~# cd /usr/local

2. Download the "j2sdk-1_4_1_01-linux-i586.bin" from www.java.sun.com into the

current directory.

3. Change the permisions on the file using:

linux:/usr/local# chmod 755 j2sdk-1_4_1_01-linux-i586.bin

4. Run the binary:

linux:/usr/local# j2sdk-1_4_1_01-linux-i586.bin

. This will create a new subdirectory, j2sdk-1_4_1_01, and install the sdk

into it after you have scrolled through the license agreement and answered

"yes" to "Do you agree to the above license terms? [yes or no]"

5. Enter:

linux:/usr/local# ln -s /usr/local/j2sdk-1_4_1_01 /usr/local/jdk

This creates a symbolic link, /usr/local/jdk, to the j2sdk-1_4_1_01

directory. This way you can have the jdk directory in the path, and

upgrade your versions merely by installing it to its own directory and then

changing the symbolic link again.

6. Append to /etc/profile:

export PATH=$PATH:/usr/local/jdk/bin

to make sure the /usr/local/jkd/bin directory (but really the

/usr/local/j2sdk-1_4_1_01/bin directory ) is in your path.

7. Reload the /etc/profile by:

linux:~# source /etc/profile

8. Enter

linux:~# javac

to check that it is properly installed.

9. Append to /etc/profile:

export JAVA_HOME=/usr/local/jdk

to tell your system where the JDK base directory can be found.

How To Install Sun One Studio:

1. Download the "j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin" file. Make sure

downloaded file is the same size as indicated on the Sun web page.

2. To change permisions run:

linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin

3. Decide on a directory( eg. /usr/local).

4. Run:

linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin

The installer will start up, ask if you agree to the license terms, and if

you say yes, it will ask which directory to install to (I chose

/usr/local/s1studio4_1_1). There is no need to be currently in that

particluar directory at the time. It will create a new directory tree in

/usr/local/s1studio4_1_1 with subdirectories _uninst, j2sdk1.4.1, and

s1studio.

5. The installer will put focus on the finish button when it's done. When you

press it, a small message box comes up saying that to start the program, you

must run runide.sh in /~/s1studio/bin to start the IDE.

6. If you HAVE NOT previously installed the jdk then append to '/etc/profile':

export PATH=$PATH:/usr/local/s1studio4_1_1/j2sdk1.4.1/bin

If you HAVE previously installed the jdk but want to use the new one, then edit '/etc/profile' to remove the export PATH line that contains your old jdk or j2sdk directory and append the new export PATH command to the profile file.

7. Append the next line to /etc/profile:

export PATH=$PATH:/usr/local/s1studio4_1_1/s1studio/bin

Save profile and exit the editor.

8. Reload the /etc/profile by:

linux:~# source /etc/profile

9. The only way I figured the following out, was by reading the runide.sh file. I found no documentation, no hint or clue elsewhere.

To start the IDE, runide.sh needs to know where the jdk is. The installation leaves it no clue, so you have to pass it a command line argument as shown:

runide.sh -jdkhome /usr/local/jdk

or

runide.sh -jdkhome /usr/local/s1studio4_1_1/j2sdk1.4.1

depending on your choice in part 6.

10. The easiest way I found to get the ide to start was to right-click the mouse on the KDE panel, then click on Add in the menu that pops up. On the next sub-menu click on SpecialButton, and next on Non-KDE Application. This will bring up a file selection box. Browse until you find the runide.sh file, and click on it. This will come up with a Non-KDE Application Configuration data-entry box. In the edit field, enter: -jdkhome /usr/local/jdk. You can click on the icon now to change it, or you can change it at any later time by simply right-clicking the icon on the panel to edit the preferences.

At this point I had an icon on the panel which I could left-click on to start the IDE.

Ron Gesell

Jan 28, 2003

Re: Getting Started with Java on Linux

Anonymous's picture

Because Tomcat is rubbish. Resin is not that expensive that the licenses price you out of running it, hell, if you're a small company and cant afford it, Caucho will let you off the hook! Go read the license terms.

Seriously, Tomcat is complete rubbish, its slow and cumbersome, and it crashes all the time. Resin is king! Long live resin!

Re: Getting Started with Java on Linux

Anonymous's picture

The above is obviously a troll and should be ignored. Probably a Resin employee giving out dubious advice.

Tomcat is deployed at large companies due to its high regard by the programmers who's jobs would be affected if it wasn't stable. I'll even name one: Universal Studios. Its filling niches where traditional proprietary costs would be prohibitive or overkill.

Its solid, has open source backing (no small thing when you consider the resources this fact brings to bear), and its Free (as in Freedom, not free beer) to use as you please on as many boxen as you please.

And, one final very important point made by another poster here. When the company that makes Resin is long gone, Tomcat will still be there due to its status as an Open Source project. How's THAT for reliability.

Re: Getting Started with Java on Linux

Anonymous's picture

Because Resin is much faster, it automagically reloads the web application when you change a class or the web.xml, etc.

Resin is free for development, you only have to pay a license for your deployment server.

Re: Getting Started with Java on Linux

Anonymous's picture

Because

* Resin is much faster

Give them time, besides, speed isn't everything

* it automagically reloads the web application when you change a class or the web.xml, etc.

Yes, even tomcat does this

* Resin is free for development, you only have to pay a license for your deployment server.

Interestingly enough, aside from the damned sun java requirement, tomcat gives you:

- freedom to use it for whatever purpose,

- freedom to maintain it even if the vendor no longer does,

- freedom to install in as many machines with as many cpus as you wish,

- freedom to resell improved copies (or even giving them away gratis)...

With all of this and you not even have to pay for a license per machine/cpu for your deployment servers... so, tell us again, please, why should an enterprise use resin instead of tomcat?

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState