10 Steps to Hosting Java on LunarPages

By | July 19, 2007

I recently created Tagxe, a peer to peer transportation website. It is coded in java as I initially wanted to develop a J2ME edition so that you can find rides using your mobile phone on the go. After coding Tagxe, I hunted around for a webhost. Alas to my dismay, Java because of its hosting complexity is not a widely supported platform for low budget hosting plans. Nevertheless I found that Lunarpages does allow Java hosting for an extra $1.99 a month. However getting it to work took some time and effort though. Searching the forums solved most of my problems but I thought I should make a tutorial so that everyone who is thinking of hosting Java on Lunarpages will be able to benefit from it.

Here is a list of things I had to do to get it to work. It is a few simple steps but if you did not know that you had to do them, you could have quite a headache trying to solve the wrong problem

1) Ask for a JSP account.
This is even after you had applied for a JSP account when you signed up for the hosting account. You will get a 404 error when you try to enter a JSP page. What you have to do it so to email tech support and ask them to activate your JSP account. After which you should be able to enter your JSP page. I have no idea why you need to do this but you have too.

2) Replace the header in web.xml.
Lunarpages uses Resin server to run Java instead of the Tomcat server commonly used by Java programmers. Because the 2 servers differ in some aspects there is bound to be some problems when you try to run a program directly. In this case, the version of web.xml language that resin use is simpler than what tomcat creates. So I had to dumb down the web.xml by replacing the header with

?xml version=”1.0″ encoding=”UTF-8″?>

!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”



**Add a “<" before each line. I cannot add in that or else blogger will think that this code is for my blog.

3) Database Naming Changes
When you code, you usually define your database name. But when you host on Lunarpages, all your database names are prefixed with your username. This means that your uploaded code should be changed so that the database code connects to the right database.

4) Setup database with your username and password
Your new database will have no user accounts assigned to it. What you now need to do is to create a new user from Lunarpage’s cPanel and assign that account to be able to access the newly created database. There might already be other databases in your account if you have installed forums or blogging software. Remember to also update your code with the new username and password.

5) Use the Default Database Connector
My database connector did not work. I am not too sure why. But if yours does not work too, here is the default code that I found.

try {


connection = DriverManager.getConnection(url,username,password);

statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);


statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);


catch (Exception myException)


System.out.println(“database exception!” + myException.getMessage());

return false;


return true

6) Timing
If your application requires the use of time, you need to either add in support of time zones or manually add in the difference in server time and where your application will be used. I changed the time by adding 15 hours so that the time became Singapore time as the server is hosted in US.

7) Copy the entire web folder into public_html
Although Lunarpages support the unpacking of WAR files, I found that if you used multiple applications to develop your code, the WAR file will not be complete. Also another strange thing is that the WAR file will unpack itself into a new folder under the webapps dir. This means that instead of accessing the homepage via www.Tagxe.com, I had to use www.tagxe.com/webapps/build. Of course this didn’t make sense. In the end, the best solution is to manually copy all the pages and code into public_html folder.

8) Debug Code Anomalies
I removed an extra semi colon in my code that caused a Classnotfound exception in Resin. Tomcat has no problems with this extra semi colon though. This is yet another example of differences in servers. At least this was relatively easy to debug as Resin told me the line number that caused the error.

9) Try to get connection pooling working in the future
While surfing the forums for the solutions above, I came across many posts with problems related to connection pooling. I guess that I might have this problem when Tagxe hits the masses and has many simultaneous connections.

10) Logging
Lunarpages does not allow you to access the logs of the resin server thus rendering you unable to read your system.out.print. There is a separate jar available for logging. I have not gotten around to using it yet but it should not be hard to use.

Above are the 10 steps you more or less need to do to get java hosting on Lunarpages. It is not too hard and so fast, the hosting of java on Lunarpages seem to be reliable and smooth running. I hope my post helps everyone. If you intend to sign up for Lunarpages, please click on my referral link here.

Lunarpages.com Web Hosting

You might also be interested in:
Top 10 Must Have Add-Ons for ThunderBird
10 Steps To Charging For Web Design

TodaysTen.com: Daily Top Ten List to jumpstart your knowledge

One thought on “10 Steps to Hosting Java on LunarPages

  1. Bryce

    Thanks for participating in The Designed Web :), this week’s edition has been published, be sure to forward any new links to the carnival


Comments are closed.