Link to home
Start Free TrialLog in
Avatar of rrasho
rrasho

asked on

Tomcat and Ant problems

Hi

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:
myapp
 -src
  -client (applets and dialog forms)
  -common (classes that i use for serialisation and communication between servlets and applets)
  -server (servlets + jdbc access)
 -web
 -docs
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?
Avatar of victorli
victorli
Flag of China image

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"  
         destdir="web/WEB-ING/classes/server"/>
  <javac srcdir="myapp/server"
         destdir="web/WEB-ING/classes/common"/>
</target>

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.
Avatar of rrasho
rrasho

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of victorli
victorli
Flag of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rrasho

ASKER

Thanx fot the help victor, i hope 20 points will be ok.
Thanks rrasho.