that work around is probably not what you want. You've just disabled the ability to reload your app correctly.
Try using another classloader, maybe the
Thread.currentThread().getContextClassLoader()

where are you storing the class that is trying to load the singleton? it should be in your webapp as well.

Filip

Mike Peremsky wrote:
I have resolved this issue, but am wondering if the way I did it is the 
"correct" way to resolve this issue.
I modified the catalina.properties file entry common.loader by adding the path to the applications WEB-INF/classes directory, this seems to have resolved the issue with finding the class. common.loader=${catalina.home}/common/classes,<snip>,${catalina.home}/webapps/myExternalApp/WEB-INF/classes I also had to fix a bug in the retrieval of the method (I read the API docs incorrectly) private static final Object OBJECT_ARG_LIST[] = new Object[0];
   private static final Class CLASS_ARG_LIST[] = new Class[0];

                 Method method = 
singletonClassObj.getMethod(GET_INSTANCE_METHOD,
                     CLASS_ARG_LIST);
               method.invoke(null, OBJECT_ARG_LIST);

Mike Peremsky <[EMAIL PROTECTED]> wrote:
  I tried the modification you suggested (with the correct method name on the 
end) but still with the same results. I also printed out a debug message just 
to see what class loader was being used (not that I know what to do with it :-P 
)

log.debug("this class loader: " + 
this.getClass().getClassLoader().getClass().getName());
Class singletongClassObj = this.getClass().getClassLoader().loadClass(singletonClassName);
The class loader for the SingletonLoader is: 
org.apache.catalina.loader.StandardClassLoader.

The classes that it is looking for are located in the
/apache-tomcat-5.5.23/webapps/myExternalApp/WEB-INF/classes directory.




Filip Hanik - Dev Lists wrote:
did you try

Class singletongClassObj = this.getClass().getClassLoader().loadName(singletonClassName);
Filip


Mike Peremsky wrote:
I think this may be a class loader issue, but am not sure as I have never really worked with them before. I am putting together a JAR file that contains a set of classes to be used throughout a suite of applications. I have a class called SingletonLoader that was working when it was within the main application, but when I broke out the reusable classes into a separate jar file and modified the contextInitialized() method to dynamically load the classes it is failing to fid the classes. The contextInitialized() method is properly reading the class names from the property file (e.g. SINGLETON_LOADER_CLASSES=com.externalApp.singleton.Countries,com.externalApp.singleton.SecurityQuestions) and looping through them, but I always get the following error message when the line Class singletongClassObj = Class.forName(singletonClassName);
is executed:

Unable to load singleton: com.externalApp.singleton.Countries
java.lang.ClassNotFoundException: com.externalApp.singleton.Countries

ALL of the singleton classes to be loaded implement the Singleton interface (which has 
nothing in it, it is just used to denote a class that MUST specify a "public static 
anyReturnVal getInstance()" method.

public class SingletonLoader implements ServletContextListener, SystemConsts {
/**
* Logger for this class
*/
private static final Logger log = Logger.getLogger(SingletonLoader.class);
private static final String SINGLETON_LOADER_CLASSES
= "SINGLETON_LOADER_CLASSES";
private static final String DELIMITER = ",";
// This is the method defined
private static final String GET_INSTANCE_METHOD = "getInstance";
private static final Object ARG_LIST[] = new Object[0];

/**
* Constructs a new SingletonLoader object.
*/
public SingletonLoader() {
}

/**
* Notification that the web application is ready to process requests.
* * Initializes all of the singletons so they are ready for immediate use
* after the containet server starts.
* * @param sce This is the event object for notifications about changes to the
* servlet context of a web application.
* */
public void contextInitialized(ServletContextEvent sce) {

log.debug("contextInitialized: BEGIN");
String singletons = ExtProperties.getProperty(SYS_PROPS, 
SINGLETON_LOADER_CLASSES);

if (!StringUtils.isNullOrZeroLen(singletons)) {
DelimitedString ds = new DelimitedString(singletons, DELIMITER);
int max = ds.size();
String singletonClassName = null;

for (int ndx=0; ndx < max; ndx++) {
try {
singletonClassName = ds.getEntry(ndx);
log.debug("Get singletonClassName: " + singletonClassName);
// Get the singleton class to load
Class singletongClassObj = Class.forName(singletonClassName);
log.debug("singletongClassObj: " + singletongClassObj);
Method method = singletongClassObj.getMethod(GET_INSTANCE_METHOD,
singletongClassObj);
method.invoke(null, ARG_LIST);

} catch (Exception e) {
log.error("Unable to load singleton: " + singletonClassName, e);
}
}
}
log.debug("contextInitialized: END");
}

/**
* Notification that the servlet context is about to be shut down.
*
* @param sce the ServletContextEvent
*/
public void contextDestroyed(ServletContextEvent sce) {
}
}

Example of the Countries singleton


public class Countries implements DbConsts, Singleton {
private static Logger log = Logger.getLogger(Countries.class);



/** Creates a new instance of Countries */
private Countries() {
refreshData();
}

/**
* Returns the single instance of this class.
*
* @return the instance of this class.
*/
public static Countries getInstance() {
if (instance == null) {
synchronized (Countries.class) {
if (instance == null) {
instance = new Countries();
}
}
}
return instance;
}


}


---------------------------------
Be a better Globetrotter. Get better travel answers from someone who knows.
Yahoo! Answers - Check it out.

------------------------------------------------------------------------

No virus found in this incoming message.
Checked by AVG Free Edition. Version: 7.5.467 / Virus Database: 269.7.1/805 - Release Date: 5/15/2007 10:47 AM



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------
Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search.

---------------------------------
Give spam the boot. Take control with tough spam protection
in the all-new Yahoo! Mail Beta.
------------------------------------------------------------------------

No virus found in this incoming message.
Checked by AVG Free Edition. Version: 7.5.467 / Virus Database: 269.7.6/814 - Release Date: 5/21/2007 2:01 PM


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to