SyntaxHighlighter

Showing posts with label Tomcat. Show all posts
Showing posts with label Tomcat. Show all posts

Friday, October 24, 2008

So long Java!

I've been struggling on and off for over two weeks to get my development environment up and running for Java web apps. I went with the JBoss Seam framework, since it was supposedly lightweight; Eclipse because it had a lot of plugins and seamed to be the most popular free IDE; Tomcat, since its what our web server is running.

In the end I had to ditch Eclipse because it has major issues with plugins cross versions. It's near impossible to get the right jar files and versions for all the Tomcat, Seam and Debugging plugins to play together. So I went with NetBeans, which seemed to be miles simpler to use, but with less functionality and a smaller community.

Even with the simpler NetBeans it was still a mission to get everything working. Finally I was ready to start doing some real coding, but oh my, what a mess!! Perhaps I'm just an idiot, but Seam doesn't have any logical (/www/myproject/...) structure and there's hundreds of XML files all over the shop. Phew... I tried to follow a few tutorials, but I was unable to find a good one. There isn't a single one that just says 1. Here is all the crazy config files, 2. Here is the code, 3. This is how it it all is structured, 4. This is how you deploy... bla bla. Come on people! Keep it simple!

After getting the examples going I read somewhere that I would need JBoss AS in order to run Enterprise Java Beans and it seemed like Seam used EJB for session management or something. Aaargh!!!! The Seam website explicitly states that you can run Seam on Tomcat, but fails to mention that you wouldn't have all the functionalities. What a load of rubbish!! Our web server only runs Apache 2 and Tomcat, so this is a bit of an issue.

I could see that ease of web development in Java is still VERY mush inferior to the likes of Asp.Net or RoR. It's almost impossible for a noob to create a simple website that queries a db with an IDE that supports debugging.

I had a quick look at PHP and it took me two days (which is also far too long for my liking) to get a full dev environment setup with Apache 2, MySql, Eclipse, PDT and Zend. After that my first application was up and running within minutes. PHP is logical, very well documented and has a huge dev community. It seems brilliant!

So that was the final blow to the head for Java. I can't understand why Java is so popular in big enterprises. Well at least for the web side of things. It's like using C++ to run a web app. It simply isn't geared for that purpose. Or perhaps I'm just missing something.

Tuesday, September 23, 2008

Get JBoss Seam going on Gentoo Linux with Tomcat

I've been given a web app to do for an open source driven organization. I like the ideology behind open source, but I must say that the complexities involved in just getting started, must be the single biggest hurdle in the adoption of OSS.

Most Java and Linux fanboys might rupture a vain for me saying this, but to get any sort of Java web app going is massive pain in butt. To get Asp.Net going, one merely install visual studio and off you go. You don't even need IIS these days. To get a Java web app (dev environment) going you have to install a web server, an application server, a java framework, an IDE, IDE plugins to support the java framework and perhaps additional frameworks / tools which will allow you to work in a "code-behind" fashion. Then you have to decide on a web frameworks and the choices are endless: Spring MVC, Struts, Seam, JSF, Tapestry, Wicket, Hibernate, Stripes, etc. You can Google until you're blue in the face, but every single framework claims to be the best and all have their own following of groupies. To be honest, it is a big geeky mess!

Unfortunately I don't have the luxury of cleaning up this steaming pile of rubbish, so I'll have to get my hands dirty and figure out what the best solution is through trial and error (very scientific).

My client already has Tomcat running, so luckily I don't have to bother about figuring out which application server is the best. A further requirement is that the web framework should be quite lightweight. It seems as if JBoss' Seam framework isn't too much of a brute, so I'll go with that and probably get burned half-way in.

Even though I detest overcomplicated systems, I've grown quite fond of Gentoo. Once you've mastered this beast, it is quite pleasant to work with. (Perhaps I'll have the same feelings towards Java web apps once I've finished here, but for now it's not looking good.) So I'll run through the steps of getting Seam going on Gentoo.

To start off with, we'll need JDK (or JRE). Login as root, emerge sun-jdk (in my case version 1.6.0.07) and logout. After that we need to get Tomcat.

Note: You can try to get Tomcat going through portage, but you'll end up pulling your hair out, because Seam uses the naming-factory-dbcp.jar, which is not included in the build for some bizarre reason.

cd ~
mkdir applications
cd applications
wget http://apache.mirrors.hoobly.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
tar -xf apache-tomcat-6.0.18.tar.gz
Now let's set the environmental variables needed:
nano ~/.bashrc
and add these lines:
export JRE_HOME=/opt/sun-jdk-1.6.0.07
export TOMCAT_HOME=/home/yourname/applications/apache-tomcat-6.0.18
export CATALINA_HOME=$TOMCAT_HOME
export CATALINA_BASE=$TOMCAT_HOME

Note: You might want to emerge the tomcat-native package, since it will add the Apache Tomcat Native library. I'm not sure if Seam needs this, but I noticed Tomcat having a bit of a fit when it couldn't find it. The message in the $TOMCAT_HOME/logs/catalina.out was "INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path"

One can also configure an admin user, but this is not necessarily required. Edit the tomcat-users.xml file like this:
nano $TOMCAT_HOME/conf/tomcat-users.xml

<tomcat-users>
<role rolename="manager">
<user username="root" password="irock" roles="manager">
</user>
One can now start Tomcat:
cd $TOMCAT_HOME/bin
./startup.sh

You should now be able to access Tomcat on http://localhost:8080

Tomcat will display $TOMCAT_HOME/webapps/ROOT/index.html

So we can now follow Seam's Tomcat guide, which I had to modify a bit:

1. Go into the jboss-seam/examples/jpa directory
2. Copy the lib/hsqldb.jar into $TOMCAT_HOME/lib
3. Run ant tomcat6 to build the application
4. Stop Tomcat $TOMCAT_HOME/bin/shutdown.sh
5. Remove previous any exiting deployments: rm -r $TOMCAT_HOME/webapps/jboss-seam-jpa
6. Copy war file: cp dist-tomcat6/jboss-seam-jpa.war $TOMCAT_HOME/webapps
7. Start Tomcat $TOMCAT_HOME/bin/starup.sh
8. Access the app at http://localhost:8080/jboss-seam-jpa

And Bob's you're uncle!