Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

directory structure in Tomcat

Posted on 2004-10-26
13
Medium Priority
?
315 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
Comment
Question by:muskad202
[X]
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
  • 7
  • 3
  • 3
13 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 160 total points
ID: 12419089
> 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
thomas908 earned 80 total points
ID: 12419839
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
ID: 12419843
You can also put ut jar files under
tomcat\common\lib

that will make it available for all webapps deployed on thatt server.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Expert Comment

by:TimYates
ID: 12419867
> 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
ID: 12420007
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
TimYates earned 160 total points
ID: 12420024
> 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
ID: 12420029
>> 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
ID: 12420046
> what's a static constructor?

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

Author Comment

by:muskad202
ID: 12420053
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
ID: 12420054
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
ID: 12420063
> (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
ID: 12420073
>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
ID: 12420077
:-) Cool :-)

Good luck with it :-)

Tim
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

610 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