Tomcat and Ant problems

Posted on 2003-03-13
Medium Priority
Last Modified: 2013-11-24

Must say that i am very beginner to java and i have to write web app. using tomcat, servlets as business logic, applets as front-end and Ant like make in C. I know some tomcat, have few servlets working in my web app. and applets are not the problem.
Problem is that i dont know how to make directory structure on tomcat. I have something like this:
  -client (applets and dialog forms)
  -common (classes that i use for serialisation and communication between servlets and applets)
  -server (servlets + jdbc access)
Now i have heard that in the web dir i should have only files that go to client like gif, html, applet classes etc.
And i need to have WEB-INF/classes dir inside this 'web' dir. But when i use Ant for build, directory structure on the 'web' and 'src' dir dont match and Ant is recompilling all files - because i need to have client classes in web/ and server in web/WEB-INF/classes. What should i do?
Question by:rrasho
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 8133662
In your build.xml file, you need to do something like this:
<target name="compile" depends="init">
  <javac srcdir="myapp/src" destdir="web/applet"/>
  <javac srcdir="myapp/server"  
  <javac srcdir="myapp/server"

Your structure are mostly OK except that you missed a "distribution" directory. If you look at some build.xml sample in the apache ant webiste "http://ant.apache.org/manual/index.html", you will find that normally there are 3 directories: source, build and dist. "Source" directory is your development area and they dont contain any class files or jar files. You compile all class files, web static files, web.xml etc to your "build" directory which completedly make a web application. You configure your tomcat's server.xml to point to this directory for your testing. In "distribution" area it contains a single jar/war file which allows you to easily deploy it on any other Tomcat instance.

Author Comment

ID: 8136062
Thanks Victor. I need to clarify it little bit more.
If i make distribution dir, where would it be? How could i call my servlets if they are jar-ed in dist dir?
Does build dir have structure like i have with web/applets and web/WEB-INF...?? Maybe then i would have to add /build/ or /dist/ in the paths or change web.xml for servlet url-patterns?

Accepted Solution

victorli earned 80 total points
ID: 8141496
Hi rrasho,

The "web" directory your named before is what i mentioned the "build" directory here.

You may put your distribution dir under "myapp" directory and called it say "distDir". In your ant build.xml file, you add a task called "distTask", this task jar/war all files/directories under "build" directory to one file say "myapp.war" and copy this file to "distDir". So the distribution dir is only for you to store distribution files as war/jar format. You may use time stamp or version number for different versions of your distrubutions.

Your web.xml should not know anything about these directory name "build" or "distDir". This configuration is done by your tomcat server through context path. In your server's configuration file "server.xml", if you put <context path="whatever_contextPath_you_want" docBase="../myapp/build">.
You can access your servlet use the url like "http://localhost:8080/whatever_contextPath_you_want/sales/servlet1". In your web.xml, you set the servlet url pattern as "/sales/servlet1" or "/purchase/servlet2".

When you need to deploy your application for your client,
you can copy the "myapp.war" to your client's server. Unwar it and you get everything exactly the same as those under "build" directory. Configure Tomcat as above and this it! Another easier way to do the deployment is copy "myapp.war" to Tomcat's "webapps" directory and restart. Tomcat will automaticall deploy it. In this way the context path is decided by Tomcat which is "myapp".


Author Comment

ID: 8150131
Thanx fot the help victor, i hope 20 points will be ok.

Expert Comment

ID: 8150973
Thanks rrasho.

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question