The Artima Developer Community
Sponsored Link

Java Answers Forum
unable to locate .class file in a jar file in classpath from an application

1 reply on 1 page. Most recent reply: Feb 10, 2006 10:58 AM by Javier Godino

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
BadriNarayanan Srinivasan

Posts: 2
Nickname: badri2379
Registered: Dec, 2005

unable to locate .class file in a jar file in classpath from an application Posted: Dec 12, 2005 9:54 PM
Reply to this message Reply
Advertisement
I have deployed my application in weblogic 8.1_sp5.The deployed application can be either in a .war file or .ear file format.This application loads a DOM object in to memory based on some settings in an xml file.The xml file is located on a particular path in the hard drive.

For eg :Let us assume the settings file is located in d:\myapplication\dist\myxml.xml.
In general, we have a home path variable,based on which we get the location of the settings xml file.Let us assume the home path variable as APP_HOME.
If the APP_HOME is set to d:\myapplication, we search for the \dist folder under that and locate the xml file.
The application also has the option of getting the path from the source code, if APP_HOME is not set(It can be achieved in the following manner).

For eg:
Let us say the jar file name is myapplication.jar(jar file that is available in the classpath).
It contains a class named as MyUtils.class.
Here we are making use of the class.getClassLoader()API (which returns a classLoader type) to get the name of the classLoader that loaded the above class into the JVM.

//The MyUtils.class code looks like this.
ClassLoader cl=MyUtils.class.getClassLoader();
//now we are getting the URL for the above class by passing the path of MyUtils.class as //its argument.
URL url=cl.getResource("com\myapp\MyUtils.class")
String path=url.getFile();

This above string path is supposed to have a value like E: \myapplication \dist \lib \myapplib.jar! com\myapp\MyUtils.class once url.getFile() is invoked.
From this, we truncate the path String and get the path for APP_HOME as e:\myapp\dist.

The problem is ...When we try like this in our application(.war or .ear file that is deployed in weblogic8.1_sp5), the url is returned as null.The .war or .ear file that is deployed is not able to locate the class file (available in the .jar file located in the classpath).
As a result we are not able to set the value for home variable.

Requesting your help in this regard.

Thanks in advance,
Badri


Javier Godino

Posts: 1
Nickname: jgodino
Registered: Feb, 2006

Re: unable to locate .class file in a jar file in classpath from an application Posted: Feb 10, 2006 10:58 AM
Reply to this message Reply
Hi:
I have the same question.
Did you get the answer?
thanks
Javier

Flat View: This topic has 1 reply on 1 page
Topic: Problem occur during runtime.......... Previous Topic   Next Topic Topic: Regular expressions  - how

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use