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 :)
LVL 2
muskad202Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
> 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thomas908Commented:
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
thomas908Commented:
You can also put ut jar files under
tomcat\common\lib

that will make it available for all webapps deployed on thatt server.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

TimYatesCommented:
> 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
muskad202Author Commented:
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
TimYatesCommented:
> 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
thomas908Commented:
>> i need to load the properties from a static constructor of a class

what's a static constructor?
0
TimYatesCommented:
> what's a static constructor?

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

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

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

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

Good luck with it :-)

Tim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.