Solved

directory structure in Tomcat

Posted on 2004-10-26
275 Views
Last Modified: 2013-11-24
hi !!

(1) i read somewhere that, if the directory structure within C:\tomcat\webapps is the correct format, then , u don't need to use ANT to deploy the appliaction, u just copy the .java files in the correct location, and when u start tomcat, it will compile the code, etc. can someone show me the proper directory structure for this ?

(2) also, the webapp uses some java libraries that need to be in the classpath. is there any way to have that path added to the classpath automatically? i don';t want to tell the client that he has to set the classpath manually.

(3) one last Q, .. i want to use a .properties file from my webapp .. where should i physically place the file? i tried placing it in the same folder as the .class files, but it didn't work .. it only worked when i placed it in c:\tomcat\bin\ but i don't want to do that, becoz, what i'm trying to do is, give the client a folder, and all that is required is to place it in c:\tomcat\webapps, i don't want to tell him to manually copy a file into c:\tomcat\bin

thanks :)
0
Question by:muskad202
    13 Comments
     
    LVL 35

    Accepted Solution

    by:
    > u just copy the .java files in the correct location

    Nope, AFAIK Tomcat will not compile java files...  just JSPs

    >  is there any way to have that path added to the classpath automatically?

    Copy the jar files into WEB-INF/lib for your webapp

    > i want to use a .properties file from my webapp

    stick it in WEB-INF/classes

    Then, to load it you can do:

        props.load( this.getClass().getResourceAsStream( "/your.properties" ) ) ;
    0
     
    LVL 8

    Assisted Solution

    by:thomas908
    Here's the diretory structure

    1.  tomcat\webapps\YourProject\WEB-INF\classes
    2.  tomcat\webapps\YourProject\WEB-INF\lib
    3.  tomcat\webapps\YourProject\WEB-INF\web.xml

    Put ut class files in 1 (Including package ofcourse)
    Put ur jars in 2. they are automaticaly added to classpath on redeployment.
    0
     
    LVL 8

    Expert Comment

    by:thomas908
    You can also put ut jar files under
    tomcat\common\lib

    that will make it available for all webapps deployed on thatt server.
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    > that will make it available for all webapps deployed on thatt server.

    But be warned, it could cause problems if you (for example) have a webapp that uses a different version of xerces or something...
    0
     
    LVL 2

    Author Comment

    by:muskad202
    hi !!
    thanks for replying :)
    one thing though .. i need to load the properties from a static constructor of a class .. but the this.getClass() requires an object .. how do i get around that ?

    i tried something like

    properties.load(new FileInputStream("../global.properties"));

    (the ../ is because the java file that loads the properties is within a package .. its physical location is web-inf\package\file)

    but it din't work :(

    thanks :)
    0
     
    LVL 35

    Assisted Solution

    by:TimYates
    > how do i get around that ?

    You can do:

        properties.load( YourClass.class.getResourceAsStream( "/global.properties" ) ) ;

    Just replace "YourClass" with the class that you are doing the loading from :-)
    0
     
    LVL 8

    Expert Comment

    by:thomas908
    >> i need to load the properties from a static constructor of a class

    what's a static constructor?
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    > what's a static constructor?

    public class SomeClass
    {
        static
        {
            // some static initialisation stuff here
        }
    }
    0
     
    LVL 2

    Author Comment

    by:muskad202
    e.g.

    --------------

    // Hullo.java

    public class Hullo
    {
            static
            {
                  System.out.println("Hello World without main!!!!");
            }
    }

    --------------

    if u compile and then run, then, it will complain that there is no main method. but, before that, it will print "Hullo world", becoz the class was loaded into memory
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    So, for my example, I would do:

    public class SomeClass
    {
        static Properties properties ;
        static
        {
            properties.load( SomeClass.class.getResourceAsStream( "/global.properties" ) ) ;
        }
    }
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    > (the ../ is because the java file that loads the properties is within a package .. its physical location is web-inf\package\file)

    The "/" at the front of "/global.properties" tells it to look in the root of the classpath, so you don't need the ".." with getResourceAsStream()

    0
     
    LVL 2

    Author Comment

    by:muskad202
    >properties.load( YourClass.class.getResourceAsStream( "/global.properties" ) ) ;

    >Just replace "YourClass" with the class that you are doing the loading from :-)

    --------
    works perfectly ... thanks :)
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    :-) Cool :-)

    Good luck with it :-)

    Tim
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT Security CISA, CISSP & CISM Certification

    Master the advanced techniques required to protect network resources from external threats with the IT Cyber Security bundle. Built around industry best-practice guidelines, the IT Cyber Security bundle consists of three in-depth courses.

    Suggested Solutions

    Title # Comments Views Activity
    either24  challenge 19 58
    Null Boolean Values? 3 28
    Using java code in .Net/c#: namespace issue 3 31
    scores100 challenge 3 49
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    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…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now