Fog Creek Software
Discussion Board




Java deployment => pain in the rear

I posted a thread entitled "which language" a few days back and got some great feedback.

I listened and pontificated, then I decided to go with Java.  So I have spent my weekend setting up Red Hat with Postgresql, Tomcat, Eclipse, Java, and what-not.

So far so good.  I even got the Postgres/JDBC connection to work with Java.

Now I just want to run a test servlet through Tomcat and I'm completely baffled.  I got this link on WAR files, but it is anything but clear.  DAMMIT!

http://jakarta.apache.org/tomcat/tomcat-3.2-doc/appdev/index.html

So if anyone has a CLEAR link with very specific, step by step instructions, please post it.

Thank you!!

newToOSS
Sunday, August 15, 2004

By the way, I've done Java linux before, but I had a sysadmin to pawn off this crap to.  Now that I have to do it, I have even more respect.

newToOSS
Sunday, August 15, 2004

First off, why are looking at tomcat docs from 2001 v3.2 when Tomcat is on version 5.0 or 4.30.  Secondly, deploying a tomcat war file is pretty easy, just copy the war file to the webapps directory and the thing is deployed.  You may need to delete the directory that tomcat unzips  after deployment and start-stop the server.  That is all.

Berlin Brown
Sunday, August 15, 2004

Dude, you need some books. There are a bunch out there but I've read and recommend the following (Yes, if you use those links and buy the books i'll get a couple of dollars in commission.):

JavaServer Pages Developer's Handbook
http://www.amazon.com/exec/obidos/ASIN/0672324385/michaelsica-20

Learning Java, Second Edition
http://www.amazon.com/exec/obidos/ASIN/0596002858/michaelsica-20

It's difficult to write a Java app without knowing Java. The tutorials on the web will not give you enough information to write anything of significant size. (I should know, I'm attempting to do the same thing now.)

Good luck with your Java learning!

michael (michaelsica.com)
Sunday, August 15, 2004

http://www.google.com/search?hl=en&ie=UTF-8&q=deploy+war+file+java+tomcat&btnG=Google+Search

the first one up from onjava will probably be a good bet.

PopCulture
Sunday, August 15, 2004

My code is in the structure

testServlet.myServlet.hello

I make the war file and drop it into webapps, restart tomcat.

What might the url be?

newToOSS
Sunday, August 15, 2004

Tomcat has been known to make peoples' eyes bleed, due to some combination of bad doc and voodoo behavior. I personally wrote a detailed guide for a company on setting it up; I used quite a lot of BOLD for warnings. Unfortunately I don't have it, just letting you know you're not dumb or anything.

I remember using 127.0.0.1 instead of localhost was important. ;)

I'd personally consider using something like Resin, but I don't really know what's available now.

Tayssir John Gabbour
Sunday, August 15, 2004

Thanks, Tayssir.

I was wondering if it was me.  I recall feeling this pain back in 2000 when I last did Java so I never went back to Java ever since.

I was convinced to come back to it.

Now I wonder if this was a good idea.

I have a lot of patience, by the way.  :)

newToOSS
Sunday, August 15, 2004

Thanks for the link, PopCulture.

newToOSS
Sunday, August 15, 2004

If all else fails -- copy the class files as a tree under

<your stuff>WEB-INF/classes


and skip the WAR file for the time being.

That is if getting your stuff running is more important just now compared to understanding WAR files (which I don't by the way).

kinda confused by Tomcat too
Sunday, August 15, 2004

I'd agree with kinda_confused_by_tomcat_too; get the plain jsps and classes working first and sort the deployment of choice (WAR, WAR+ant, whatever) afterwards.

Under webapps, make your directory, say "pain" and add further directories so that it looks like:

/pain  (JSPs)
/pain/WEB-INF (configuration stuff, classes, libs)
/pain/WEB-INF/classes (with further subdirectories to match your package naming e.g. com/blah/blah)
/pain/WEB-INF/lib

If you need other files (e.g. images) available to the outside world, put them in directories under /pain and not WEB-INF.

Depending on what you are doing, you may need some configuration in the web.xml file that sits directly under WEB-INF.

Next, you must configure server.xml (in /tomcat/conf). You will need to make reference to the /pain application and within that have an entry that describes how you will access postgres including path, userid, password and driver. (as a previous poster mentioned, used 127.0.0.1 not localhost if on the same machine).

Make you sure you stick your jdbc driver in /tomcat/common/lib (it doesn't seem to pick it up if you have it in /tomcat/webapps/pain/WEB-INF/lib).

Start up tomcat. And go to http://localhost:8080/pain/nameofjsp.jsp and voila.

Pain in the rear? Maybe but once you have the configuration sorted Tomcat is absolutely rock solid. An excellent choice.

It's well worth having the Tomcat manager running. You will need to add a manager user in /tomcat/conf/tomcat-users.xml (something like <user username="blah" password="secret" roles="admin,manager" />). From http://localhost:8080/ you will see the Tomcat welcome screen which has a link to the manager app. You can use this to find out whether or not your app is deployed. You can also restart and load single apps without restarting the server. (You can also see how much memory Tomcat is using).

Slough Bloke
Sunday, August 15, 2004

> Why in fuck do I need a book to run a fucking servlet!?

Servlets are easy, but then if you go to the bookstore you'll be surprised at how many books are written to prevent you from shooting yourself in the foot with even simple technologies. If you are using Microsoft stuff for a while, you'll notice just about every problem you might have is covered in 5 trillion online forums which you can google out. I think you are just spoiled. You are a DIYer, and duh ServletsAreEasy! You have been able to do whatever you need, and google will back you up (or JOS, in this case). However online docs are always spotty, regardless of domain or Microsoft/Linux, and you'll have to learn to justify to yourself and your clients that proper documentation is required. I was wondering why companies are spending USD$4000+ for huge series for Microsoft documentation on dotnet framework and MSDN, but at least now I wonder no more. It really depends on the depth of the question/problem.

Li-fan Chen
Sunday, August 15, 2004

newToOSS: the URL has nothing to do with the class structure of your servlet. Your WAR file needs to contain an XML file called web.xml in its root directory. Within the web.xml, you define the servlet and map it to a URL. The Servlet spec includes the DTD for the web.xml file and the Tomcat installation probably includes an example or two.

Beth
Sunday, August 15, 2004

I'm not proud to say it, but I spent almost a whole weekend night wrestling with an early version of Tomcat several years ago on the deployment thing.  It's quite simple and devastatingly reliable once you get the concepts down.

Tomcat is good.  The documentation is (now at last) fair.  You would be throwing in the towel very, very early and without strong actual justification if webapp deployment brings you down.

Protocol adventurer
Sunday, August 15, 2004

Slough Bloke....

Thank you!  Your instruction was exactly what I needed.
You knew exactly what I was screaming about, I see.


Cheers!

newToOSS
Sunday, August 15, 2004

"c'mon, people.  I KNOW THE FREAKING LANGUAGE.

I just don't know this war shit.

Thanks anyway.  I'm beyond frustrated, don't need the condescending crap.

Why in fuck do I need a book to run a fucking servlet!?

I built the war file and dropped it in the webapps folder and restarted tomcat but no go.

Shit."

Jesus dude, I was trying to point you towards the references that helped me.

I didn't mean that as condescending "crap".

Explaining and trouble shooting J2EE stuff can be very frustrating and typing out the explaination is tedious as hell. Especially when there are tons of great books that explain everything. That JSP book basically breaks down how to setup all the web stuff, including servlets. And you'll soon realize you won't need to use servlets for anything. (Business logic goes in regular class files, view stuff goes in JSP, and remote calls would be better served through web services or EJB's, both of which are explained in that JSP book.)

And since you have a potty mouth I'm not going to mention the SpringFramework over at http://www.springframework.org. Oops.

michael (michaelsica.com)
Monday, August 16, 2004

Glad it helped.
Cheers

Slough Bloke
Monday, August 16, 2004

"Servlets are easy, but then if you go to the bookstore you'll be surprised at how many books are written to prevent you from shooting yourself in the foot with even simple technologies." --Li Fan Chen


Well, I have a subscription to Safari and I thought an O'Reilly book or two would be enough.

I have plenty of books and resources, they just leave out pertinent tidbits and force me into trial and error madness.

I think the Servlet set up is far from intuitive, and there should be a very specific instruction, similar to Slough Bloke's, on the web somewhere.

It never takes me a whole day to set up things...all the software on one machine for my initial test bed means this process should have taken half a day, at most!

That's what I get for using free tools.

A whole day of hassle and downloading.

Or maybe I'm just a complete idiot.  Naaah, that couldn't be it.

newToOSS
Monday, August 16, 2004

"
And since you have a potty mouth I'm not going to mention the SpringFramework over at http://www.springframework.org. Oops."


Haw haw.  I wasn't directing the swearing at anyone in particular.  Just the air.

I had a goal for today and I wasn't gettin' there!

Thanks for the help.

I don't plan on using servlets much, if at all....I just wanted a test to work so I can understand the configuration.

Spring looks pretty neat.  I am reading about it now...

newToOSS
Monday, August 16, 2004

http://www.coreservlets.com/Apache-Tomcat-Tutorial/

Incomparable. Got my development team through the setup quickly and easily.

Squirrel
Monday, August 16, 2004

A gold star for Slough Bloke.

example
Monday, August 16, 2004

Bloody hell, I haven't had one of them since I was at school.

Slough Bloke
Monday, August 16, 2004

Uninstall Java and install Python instead.

muppet
Monday, August 16, 2004

newToOss, no problem man. i'm sure we've all been there.

michael (michaelsica.com)
Monday, August 16, 2004

As a server-side Java developer,  in this instance I'd probably have to agree with muppet! :-)

  The thing I might be missing is what you want to do with this, but my impression is that there's a good chance that Python might be better suited to your needs....

Gwyn Evans
Wednesday, August 18, 2004

By the way, for a decent guide to Web Applications, you might want to have a look at http://www.caucho.com/resin-3.0/webapp/index.xtp although you should be aware there are some Resin[1] specific bits in there, but it should be worth a look.

[1] Resin's an alternative Servlet engine.  Tomcat's a very popular one, but there are other popular one's such as Resin & Jetty.  Personaly, I've always found Resin to be easier to work with than Tomcat, but they should all be relatively interchangable.
- The one specific bit that I noticed was that Resin will compile .java files you place in the WEB-INF/classes/ tree for you, rather than you having to do that step by hand. 

Gwyn Evans
Wednesday, August 18, 2004

*  Recent Topics

*  Fog Creek Home