Solved

How do I employ a "deployment descriptor" for a Java business class in both stand-alone and servlet context

Posted on 2007-11-19
1
187 Views
Last Modified: 2013-11-24
I am attempting to build my first Java application, with an initial goal of making it a web app.  I have followed the MVC convention and placed all of the business logic in a separate class (the Model).  I am unclear how to create a configuration file for this Model class for things like datasource information.  In my research it has been very clear how configuration works for servlets (a deployment descriptor: web.xml).  What isn't clear is how I can utilize some similar configuration scheme for the Model class, such that it will work when deployed as part of a servlet app but also as a class included by a non-web Java app (such as the test harness I built for the Model class). It seems I could use web.xml for the model class when it is part of a servlet, but then how would it work in a standalone app? The ideal solution won't make me use two different methods for using the class in a servlet vs in a standalone app.
0
Comment
Question by:bluegreenone
1 Comment
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 500 total points
ID: 20318106
Most people put configuration information (for non-Web apps) into a properties file, sometimes named myapp.properties.  It's in the name=value format, so it can easily be read using the methods of the Properties class.  You can put myapp.properties in the same directory as your class files, or in your .jar file (often in the top directory, but location varies).

Then, in your web.xml file, you could put the location of the myapp.properties file, which is then used to read the properties for your model class.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json example 39 132
how do i compare an object based on two fields 6 49
Java Loop 6 49
Arrays.asList  VS  ArrayList 4 45
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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

920 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

15 Experts available now in Live!

Get 1:1 Help Now