Link to home
Start Free TrialLog in
Avatar of muskad202
muskad202

asked on

directory structure in Tomcat

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 :)
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland 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
SOLUTION
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 thomas908
thomas908

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

that will make it available for all webapps deployed on thatt server.
> 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...
Avatar of muskad202

ASKER

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 :)
SOLUTION
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
>> i need to load the properties from a static constructor of a class

what's a static constructor?
> what's a static constructor?

public class SomeClass
{
    static
    {
        // some static initialisation stuff here
    }
}
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
So, for my example, I would do:

public class SomeClass
{
    static Properties properties ;
    static
    {
        properties.load( SomeClass.class.getResourceAsStream( "/global.properties" ) ) ;
    }
}
> (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()

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

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

--------
works perfectly ... thanks :)
:-) Cool :-)

Good luck with it :-)

Tim