Java issues and tips

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.

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

  1. open a terminal
  2. 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.

To get to the Available Plugins list, select

  1. Tools –> Plugins –> Available Plugins
  2. Check [✔] Java Web Applications and Tomcat then select Install
  3. Once it installs the plugins it will prompt you to restart netbeans.

-) Set up the Tomcat Server

When netbeans restarts, add the tomcat server. Select

  1. Tools –> Servers –> Add server –> Tomcat 6.0 –> Next >
  2. Fill in Catalina Home: as /usr/share/tomcat6
  3. Check (✔) the box for Use Private Configuration Folder (Catalina Base)
  4. 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
  5. 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.
  6. 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

  1. File –> New Project
  2. in the column Categories: select Java Web
  3. in the column Projects: select Web Application
  4. select Next >
  5. Enter your Project Name: or keep the default.
  6. Enter your Project Location: or keep the default.
  7. Select Next >
  8. 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.
  9. the rest of that page can be left at the default settings. So, select Finish as the final step.

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.

Greg Priest-Dorman 2009/09/30 16:41