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
189 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
Oracle SQL syntax check  without executing 6 74
check java version using powershell 13 168
throw exception 21 58
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

808 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