Java issues and tips

Java remote method invocation problem

Problem: When running a demo of Java's remote method invocation on our Ubuntu 9.04 based linux machines running java-6-openjdk the client could only attach to a server running on the same host.

Solution: Professor Ellman discovered that the fix is to explicitly tell the server its hostname or IP address. This is accomplished by adding ``-Djava.rmi.server.hostname=[IP or Name of HOST]`` to the java command when starting the server, so for a server named ``hopper`` with an IP address of ``10.0.0.63`` you can do either:

java -Djava.rmi.server.hostname=hopper hellormi.HelloServer

or

java -Djava.rmi.server.hostname=10.0.0.63 hellormi.HelloServer

both of which worked.

Without specifing this option the server is only listening on the loopbak device.

Adding Java Web with Tomcat 6 to Netbeans 6.5

Note: these instruction are for the setup in the Vassar College Computer Science Department Lab. They may contain information not appropriate to an install elsewhere.

0) Overview

This setup will let you run your own tomcat webserver on the local machine for building and debugging apps in netbeans. There is one command to be typed in a terminal, all other steps will be preformed from within netbeans. Total time to complete these steps will depend more upon download speed of the plugins than any other factor, but it seems to take under 10 min. from the Lab. These instruction were tested with netbeans 6.5 and tomcat 6 installed from apt-get in ubuntu 9.04.

-) Create a local copy of the needed tomcat files

open a terminal

enter the command

tomcat6-instance-create ~/mytomcat

-) Open Netbeans

Netbeans can be invoked either by typing ``netbeans`` in a terminal, or by menu selection. In Xfce4 it is on the ``Development`` menu.

-) Install Additional Plugins

You will need the plugins ``Java Web Applications`` and ``Tomcat``.

Depending on what you have done with netbeans in the past,
some or all the needed plugins may already be installed. If you do not see one of the named plugins in the ``Available Plugins`` list, check the ``Installed`` tab. If it is there you have that one already.

Fill that in with the name of the directory you created in the first step, you will need to give it the absolute path. (Replace ??YOUR_USER_NAME?? with your user name.) Enter ??/home/YOUR_USER_NAME/mytomcat??

Fill in something in the ``Username`` and ``Password`` fields. It will create this user. It stores the username and password in plain text in the file conf/tomcat-users.xml in your mytomcat directory, so don't use a valuable password. If you forget it, you can look at in netbeans or get it from the file.

Check (✔) the box labeled ``Enable HTTP Monitor``

When you select ``Close`` netbeans will save your server settings.

You can now begin a project using your Tomcat server

To do this, select

``File`` –> ``New Project``

in the column ``Categories:`` select ``Java Web``

in the column ``Projects:`` select ``Web Application``

select ``Next >``

Enter your ``Project Name:`` or keep the default.

Enter your ``Project Location:`` or keep the default.

Select ``Next >``

for ``Server:`` you should either see Tomcat 6.0 or if you have used netbeans with other servers before, you will get a pull down list of servers you have already added. If the latter, select Tomcat 6.0.

the rest of that page can be left at the default settings. So, select ``Finish`` as the final step.

Tomcat server can't start because one is already running on that port particular

There are two likly causes of this. They each have a different solution. If you have a server running you can stop it. Sometimes, netbeans will think it has not started the tomcat server when it has. That can lead to this problem. If this happens, you must stop the server outside of netbeans (netbeans will not even give you the option so stop it as it does not think it is running). To stop the server from the command line, use the shutdown.sh script in your mytomcat/bin directory:

~/mytomcat/bin/shutdown.sh

Should do it. If it does not, then someone else has a server running. If that is the case you should do two things,

Write me, tell me the name of the machine, the time of day and the ``Server port`` listed when you look at the server properties (``Tools`` –> ``Servers``)

Change your server to run on a different port.

``Tools`` –> ``Servers`` –> ``Server Port``, increment it a bit. ``Close``. See if that helps.