Influencing JAR order for Application Class Loader
I have seen some questions about this in the past but there has never been a definitive
reply one way of the other.
Is it possible to influence the order in which the web application class loader
looks through the JAR files located in the /WEB-INF/lib directory?
I have two JAR files - one contains the base release version of some software
and the other contains some fixes so I need the fixes JAR to be loaded first.
Thanks
Gary Johnson
Hi Gary,
The order jars searched in WEB-INF/lib is not defined.
You may cosider merging those two jars in one jar.
Regards,
Slava Imeshev
"Gary Johnson" <[email protected]> wrote in message
news:[email protected]..
>
> I have seen some questions about this in the past but there has never been
a definitive
> reply one way of the other.
>
> Is it possible to influence the order in which the web application class
loader
> looks through the JAR files located in the /WEB-INF/lib directory?
>
> I have two JAR files - one contains the base release version of some
software
> and the other contains some fixes so I need the fixes JAR to be loaded
first.
>
> Thanks
> Gary Johnson
Similar Messages
-
Application Class Loader problem calling virtual function
Hello everyone
I have run in to very strange behavior of JVM
I have created a class loader which allows my to load classes from
jar file, regardless that URLClassLoader supplies this functionality.
I am using this class loader to load some classes and call their virtual functions. The class diagram looks like that:
public interface I {
public void init();
public class AAA implements
public void init(){
public class BBB extends AAA{
public void init(){
//here comes implementation
}Interface I and class AAA are loaded with System Class loader and Class BBB is loaded using my class loader from jar file.
ByteStreamClassLoader classLoader = new ByteStreamClassLoader ();
Class cl = classLoader. loadClass(�com.product.BBB�,true);
I myInterface = cl.newInstance();
myInterface.init();The problem is that from some unknown reason java class AAA.init() instead of BBB.init().
Can somebody help me what am I doing wrong?
Class Loader code attached below
public class ByteStreamClassLoader extends ClassLoader {
protected HashMap m_cache = new HashMap();
public void clearCashe() {
m_cache = new HashMap();
private String definePackage(String className) {
StringBuilder strB = new StringBuilder();
//Class name must be removed from the URI in order to define a package
String[] packageArray = className.split("\\.");
for (int i = 0; i < packageArray.length - 1; i++) {
strB.append(packageArray).append(".");
String packageName = strB.toString();
packageName = packageName.substring(0, packageName.length() - 1);
if (getPackage(packageName) == null) {
m_logger.log(Level.FINEST, "Defining package '" + packageName + "'");
definePackage(packageName, null, null, null, null, null, null, null);
return packageName;
public synchronized Class loadClass(String name, boolean resolve) throws
ClassNotFoundException {
name = name.replaceAll("/", ".").replaceAll(".class", "");
//Try to locate the Class in cashe
Class c = (Class) m_cache.get(name);
//Try to locate the Class in the System Class Loader
if (c == null) {
try {
c = ClassLoader.getSystemClassLoader().loadClass(name);
catch (Exception ex) {}
else {
m_logger.log(Level.FINEST, "Class '" + name + "' found in cache");
//Load the class from byte array
if (c == null) {
String resourceName = name;
if (!resourceName.endsWith(".class")) {
resourceName = resourceName.concat(".class");
//Retrieve class byte representation
if (resourceName.indexOf(".") != -1) {
resourceName =
resourceName.replaceAll("\\.", "/").replaceAll("/class", ".class");
//Use the ByteStreamClassLoader to load the class from byte array
byte[] classByteArray = null;
try {
classByteArray = getResourceBytes(resourceName);
catch (IOException ex1) {
throw new ClassNotFoundException(
"Could not load class data." + ex1.getMessage());
m_logger.log(
Level.FINEST, "Loading class '" +
name + "' Byte Length: " + classByteArray.length);
String p = definePackage(name);
c = defineClass(
name,
classByteArray,
0,
classByteArray.length,
ByteStreamClassLoader.class.getProtectionDomain());
m_cache.put(name, c);
if (resolve) {
resolveClass(c);
return c;Hello everyone
I have run in to very strange behavior of JVM
I have created a class loader which allows my to load classes from
jar file, regardless that URLClassLoader supplies this functionality.
I am using this class loader to load some classes and call their virtual functions. The class diagram looks like that:
public interface I {
public void init();
public class AAA implements
public void init(){
public class BBB extends AAA{
public void init(){
//here comes implementation
}Interface I and class AAA are loaded with System Class loader and Class BBB is loaded using my class loader from jar file.
ByteStreamClassLoader classLoader = new ByteStreamClassLoader ();
Class cl = classLoader. loadClass(�com.product.BBB�,true);
I myInterface = cl.newInstance();
myInterface.init();The problem is that from some unknown reason java class AAA.init() instead of BBB.init().
Can somebody help me what am I doing wrong?
Class Loader code attached below
public class ByteStreamClassLoader extends ClassLoader {
protected HashMap m_cache = new HashMap();
public void clearCashe() {
m_cache = new HashMap();
private String definePackage(String className) {
StringBuilder strB = new StringBuilder();
//Class name must be removed from the URI in order to define a package
String[] packageArray = className.split("\\.");
for (int i = 0; i < packageArray.length - 1; i++) {
strB.append(packageArray).append(".");
String packageName = strB.toString();
packageName = packageName.substring(0, packageName.length() - 1);
if (getPackage(packageName) == null) {
m_logger.log(Level.FINEST, "Defining package '" + packageName + "'");
definePackage(packageName, null, null, null, null, null, null, null);
return packageName;
public synchronized Class loadClass(String name, boolean resolve) throws
ClassNotFoundException {
name = name.replaceAll("/", ".").replaceAll(".class", "");
//Try to locate the Class in cashe
Class c = (Class) m_cache.get(name);
//Try to locate the Class in the System Class Loader
if (c == null) {
try {
c = ClassLoader.getSystemClassLoader().loadClass(name);
catch (Exception ex) {}
else {
m_logger.log(Level.FINEST, "Class '" + name + "' found in cache");
//Load the class from byte array
if (c == null) {
String resourceName = name;
if (!resourceName.endsWith(".class")) {
resourceName = resourceName.concat(".class");
//Retrieve class byte representation
if (resourceName.indexOf(".") != -1) {
resourceName =
resourceName.replaceAll("\\.", "/").replaceAll("/class", ".class");
//Use the ByteStreamClassLoader to load the class from byte array
byte[] classByteArray = null;
try {
classByteArray = getResourceBytes(resourceName);
catch (IOException ex1) {
throw new ClassNotFoundException(
"Could not load class data." + ex1.getMessage());
m_logger.log(
Level.FINEST, "Loading class '" +
name + "' Byte Length: " + classByteArray.length);
String p = definePackage(name);
c = defineClass(
name,
classByteArray,
0,
classByteArray.length,
ByteStreamClassLoader.class.getProtectionDomain());
m_cache.put(name, c);
if (resolve) {
resolveClass(c);
return c; -
System class loader vs application class loader
Hello
I have a class that uses a third partyjar which I have put in /jre/lit/ext. The class compiles but fails at runtime being unable to read the property files called in the class' constructor. I believe that is b/c the third party jars are loading w/ the system class loader and cannot "see" the property files "floating" at the same level as the class that is calling them.
So I created a jar, of the property files, with the same directory/package structure as the location of the property files and put that in the /jre/lib/ext and STILL the same problem; cannot read the property files, the constructor fails, fugly. There is an overloaded constructor that includes a parameter for the property files, but I need to get this to work as is first. What am I missing? Please edify me. tia.If the 3rd party jar needs a certain properties file to initialize correctly, I doubt it would be looking for it in the class hierarchy. I mean I doubt it does:
Properties p = new Properties();
p.load( getClass().getResourceAsStream() );It's more likely to do:
Properties p = new Properties();
p.load( new FileInputStream(...) );The reason is that the property file should be easily edited by the user and users know how to move around in the file system, not in the Java jars and classpaths.
Just a guess... -
Design patterns for Dynamic Class Loading
Hi,
I have to develop a program for uni that dynamically loads classes based on names in a text file. All the classes subclass an abstract class with a constructor that takes one argument. This means I can't use the Class.forName(className).newInstance() method of class loading. I have researched some design patterns I could use and have come up with the following 3:
Factory pattern; "Robocode" pattern (not it's real name, but Robocode uses it); and, the "one I made up myself" pattern.
The robocode pattern instantiates a class using the default no-argument constructor then immediately sets all properties that shoud have been provided in the constructor:
Object o = Class.forName(myClass).newInstance();
o.setProperty(property);Personally I think this is ugly and a cheap fix instead of doing it properly.
My own pattern finds the constructor that takes the arguments I need then calls it to create the object:
Class c = Class.forName(myClass);
Constructor cons = c.getConstructor(new Class[]{Class.forName("java.lang.String")});
Object o = cons.newInstance(new Object[]{"hello"});What's the best to use? Are there any other patterns I should consider?My own pattern finds the constructor that takes the
arguments I need then calls it to create the object:
Class c = Class.forName(myClass);
Constructor cons = c.getConstructor(new
Class[]{Class.forName("java.lang.String")});
Object o = cons.newInstance(new Object[]{"hello"});
I have followed this basic 'pattern' several times though I would use
Constructor cons = c.getConstructor(new Class[]{String.class});
It works great. -
JAR File for Channel-Class for Adapter-Modules
Hello,
does anybody know which JAR and Package i need for the Channel-Class.
It's not:
com.sap.aii.mapping.lookup.Channel
I need this one with the method "getValueAsString" in order to write an Adapter-Module.
GunnarHi,
Check out this link for the documentation of com.sap.aii.mapping.lookup.
You will get all the functions of this. and import com.sap.aii.mapping.lookup and use the function of this package.
Link : http://help.sap.com/javadocs/NW04S/SPS09/pi/com/sap/aii/mapping/lookup/class-use/Channel.html
hope this will help you.
Regards
Aashish Sinha
PS : reward points if helpful -
Jar file for tcRequestOperationsIntf class
Hi,
Could you please let me know the jar file name where tcRequestOperationsIntf class is present. I need to do some API operation using this class.
Please help.
ThanksHi Kevin,
Thanks for sharing such a useful link.
I followed the step mentioned in the link shared by you, but I am getting the following error message :
java.io.InvalidClassException: oracle.bpel.services.common.exception.ServicesException; local class incompatible: stream classdesc serialVersionUID = 1, local class serialVersionUID = -2263933888849127134
Please let me know if you know how to solve this issue.
Thanks again for the help. -
Every time I go to a site I end up having to stop loading and then reload a page before it will come up. I have waited as long as 2 minutes to see if the pages will come up. It especially happens when clicking on a link. The link can be from google or a web page. I did not have this problem before updating to 8.0.1
Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
*Don't make any changes on the Safe mode start window.
*https://support.mozilla.com/kb/Safe+Mode
A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
See:
*https://support.mozilla.com/kb/Server+not+found
*https://support.mozilla.com/kb/Firewalls
You can also try to reset (power off/on) the router. -
How can I make .jar files for applications?
My jar program creates jar files but won't open the program when I double click them. I use the command:
jar cvf *.jar filenames
The jar file is created but won't execute. Can anyone tell me what i am doing wrong?
Thanks
JibyHello !
Well, I had the same problem a week or two ago !
First, in your *.java, don't use any package...I mean, don't do a package of your program (I guess there is a way to make it work with, but it would need a little bit more work...).
Then, with the jar tools, use the command
-jar cf jar_that_you_want_to_create.jar class-that_you_include_in_your_jar.class
With that, a jar will be created, and when you will try to "run" it, it will say that it can not find the main class...
You need a Manifest !
Create a text file MyManifest.text, and write that in your text file :
Main-Class: classname
follow the same as i wrote above. leave a blank after colon and a blank line after the first line like above.
then, well, use tha jar tool again:
-jar umf MyManifest.txt jar-file-you-created.jar
To "run" it, double click on it, or use the java tool:
java -jar jar_you_created.jar
Thanks to Phani, who helped me with that !!
Splitsch -
I have a set of Jar files which i need to load using Custom Class Loader. Any one who has Javacode for Custom Class Loader for loading Jar files send it. The Jar files are local jar files.
Here is the class loader I use:
import java.net.URL;
import java.net.URLClassLoader;
import java.net.JarURLConnection;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
import java.util.jar.Attributes;
import java.io.IOException;
* A class loader for loading jar files, both local and remote.
public class JarClassLoader extends URLClassLoader {
private URL url;
private URL[] m_urlList = new URL[10];
* Creates a new JarClassLoader for the specified url.
* @param url the url of the jar file
public JarClassLoader(URL url,ClassLoader cl) {
super(new URL[] { url },cl);
this.url = url;
public JarClassLoader(URL[] urlList,ClassLoader cl) {
super( urlList,cl);
this.m_urlList = urlList;
* Returns the name of the jar file main class, or null if
* no "Main-Class" manifest attributes was defined.
public String getMainClassName() throws IOException {
URL u = new URL("jar", "", url + "!/");
JarURLConnection uc = (JarURLConnection)u.openConnection();
Attributes attr = uc.getMainAttributes();
return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
* Invokes the application in this jar file given the name of the
* main class and an array of arguments. The class must define a
* static method "main" which takes an array of String arguemtns
* and is of return type "void".
* @param name the name of the main class
* @param args the arguments for the application
* @exception ClassNotFoundException if the specified class could not
* be found
* @exception NoSuchMethodException if the specified class does not
* contain a "main" method
* @exception InvocationTargetException if the application raised an
* exception
public void invokeClass(String name, String[] args) throws ClassNotFoundException,
NoSuchMethodException,
InvocationTargetException
Class c = loadClass(name);
Method m = c.getMethod("main", new Class[] { args.getClass() });
m.setAccessible(true);
int mods = m.getModifiers();
if (m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) {
throw new NoSuchMethodException("main");
try {
m.invoke(null, new Object[] { args });
} catch (IllegalAccessException e) {
// This should not happen, as we have disabled access checks
} -
Class Loader Hierarchy in Weblogic 7.0
I have read the BEA documentation on the class loader hierarchy in Weblogic Server,
and I have some questions regarding some behavior I am seeing.
I am running Weblogic Server 7.0.
I have an ear file that contains 3 web apps (wars) and several utility jars. The
web apps' manifests contain the Class-Path entry for the utility jars. My understanding
of this is that each web app SHOULD have its own class loader. Also, the utility
jars will be scoped in a separate class loader and WILL NOT have visibility to
the web app classes. The web app classes should have visibility to the utility
jars.
Is this correct????
I added a static segment of code in each web app and printed the class loader
for each servlet when it was loaded. I also printed the class loader from a class
that is DEFINITELY contained in one of the utility jars. Here is the result:
Utility Class ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Utility Class
Parent ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
Servlet 1 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet 1 Parent
ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
Servlet 2 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet 2 Parent
ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
I'm a little confused.... I expected to see 3 different class loaders (i.e. one
for each class above). I believe the above printout says that all 3 classes are
being loaded by the SAME class loader instance (Launcher$AppClassLoader@b9d04).
Am I interpreting this correctly? If so, what's going on?I rechecked the classpath for the user that starts Weblogic, and in the classpath
I found the project "src" directory (must have missed it earlier). When we did
our build, the classes are placed in the src structure then copied to the build
area. That's the reason I was not seeing the appropriate class loader hierarchy.
Thanks for all of the comments.
"Sanjeev Chopra" <[email protected]> wrote:
>
"Mark Cotherman" <[email protected]> wrote in message
news:[email protected]...
Thanks for your comments again Mark. I'm just trying to get a goodhandle
on how
this is working.
I'll assume that somehow my web app classes are being loaded into theroot
classloader.
The next question is... why??Just to be sure - is there any way these classes are sneaking into the
system classpath ?
My ear file contains the following:
a.war
b.war
c.war
lib/util1.jar
lib/util2.jar
lib/util3.jar
lib/util4.jar
The manifest in all three wars reference all util jars. This ear deployssuccessfully
on Weblogic with no errors.
How could these separate servlets (one in each war) not have seperateclass loaders
seperate from the root where the utils should reside. I don't thinkthat
I have
any control over where Weblogic loads the war classes, or do I?
See comments below....
Mark Spotswood <[email protected]> wrote:
Mark Cotherman wrote:
Thanks for the follow-up.
I want to make sure I follow what you are saying. All classes in
the
manifest
Class-Path of WARs are exported to the parent classloader.That's right.
To me this is the correct behavior since the manifest Class-Path
is
meant to provide
a way to share common utility classes among several web apps. AllEJB jars and
manifest Class-Path entries should be loaded by the same class loader.Its a way to share class definitions, but not necessarilly class
instances. I don't think that a web application should be extending
the classpath of its parent's classloader. This leads to namespace
problems as well as reloadability issues.
Ok, you lost me here. Shouldn't delegation handle the namespacecollisions??
If the web app class loader has a class definition (webapp:com.xyz.ClassA) with
exactly the same name in the same package as the root class loader(rootloader:
com.xyz.ClassA), I thought the web app would use (delegate loading)the
class
definition from the root class loader when PreferWebInf is set to false.
Isn't this why the PreferWebInf attribute, when set to true, can causeClassCastExceptions??
The web app when creating an instance of (webapp: com.xyz.ClassA)from
the web
app class loader can potentially pass a reference to this instanceto a
class
instance loaded from the root loader. The root class loader has adifferent class
definition for ClassA.
REALLY what makes since is that all common jar files be defined
in
the manifest
Class-Path OF THE ear FILE (if the WAR(s) are in an ear). These
jar
files should
then be loaded by the same class loader as the EJB jars. There shouldbe no need
for the WARs to have any reference to the utility jars since the
EJB
class loader
is the parent of the WAR class loaders.The ear file doesn't have a manifest classpath, but what you are getting
at makes sense. If you add a manifest to any EJBs in your app, theall
webapps (as well as all other EJBs) will be able to see it, sincewith
our structure, EJBs are loaded into the application's root classloader.
My problem is that the ACTUAL SERVLET classes are NOT being loadedby a separate
class loader from the EJB and common jar class loader. This is
completely
against
what is being said in the Weblogic documentation. The Manifest
Class-Path
should
have nothing to do with where the classes that reside in
WEB-INF/classes
of my
servlet are loaded.Classloaders will ask their parent for the class first before loading
it
themselves. So if the parent classloader somehow has visibility to
classes that your webpapp references, then it will get loaded by the
parent classloader.
I am in the middle of migrating an app from an older version of
Weblogic,
and
it would be helpful to have the ACTUAL class loading hierarchy welldocumented.
The basic hierarchy is all EJBs are in a root shared classloader and
each web application is loaded by a classloader that is a child of
that root.
Again, am I missing something here???My suspicion is that somehow these servlets are in the classpath ofthe
root classloader, so when the webapp classloaders delegate to thatone,
it will come up with the class.
mark
Mark Spotswood <[email protected]> wrote:
I believe what you are seeing is a bug in the servlet container.
The classloader organization is what you expect, but each webapp
is exporting the classpath information from its manifest to the
classloader above its classloader (which is common to all
three webapps) rather than to its own classloader. So because
of the delegation that happens with classloading, the common
parent classloader is the one that loads the class.
I believe that this behavior exists as an attempt to avoid
ClassCastExceptions, but I don't think that it is the right
solution to this problem. In our 8.1 release, this behavior
has been changed. That is, web applications no longer export
manifest classpath information to the parent of their classloader.
This change has not been ported back to the 7.x line, but a bug
report has been created (CR099889). You should be able to follow
up with support with this CR number.
mark
Mark Cotherman wrote:
I have read the BEA documentation on the class loader hierarchy
in
Weblogic Server,
and I have some questions regarding some behavior I am seeing.
I am running Weblogic Server 7.0.
I have an ear file that contains 3 web apps (wars) and several
utility
jars. The
web apps' manifests contain the Class-Path entry for the utility
jars.
My understanding
of this is that each web app SHOULD have its own class loader.
Also,
the utility
jars will be scoped in a separate class loader and WILL NOT have
visibility
to
the web app classes. The web app classes should have visibility
to
the utility
jars.
Is this correct????
I added a static segment of code in each web app and printed the
class
loader
for each servlet when it was loaded. I also printed the class loaderfrom a class
that is DEFINITELY contained in one of the utility jars. Here is
the
result:
Utility Class ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04
Utility
Class
Parent ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
Servlet 1 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet1 Parent
ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
Servlet 2 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet2 Parent
ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
I'm a little confused.... I expected to see 3 different class loaders(i.e. one
for each class above). I believe the above printout says that all
3
classes are
being loaded by the SAME class loader instance
(Launcher$AppClassLoader@b9d04).
Am I interpreting this correctly? If so, what's going on? -
RMI and the class loader delegation model
Hello,
I need to know what the class loader delagation chain looks like when RMI does dynamic class loading. What is the RMIClassLoader's parent? Does it delegate to Thread.currentThread().getContextClassLoader()?
In a test application I can debug the chain which looks like this:
sun.misc.Launcher$AppClassLoader@bac748
sun.misc.Launcher$ExtClassLoader@7172ea
The AppClassLoader is the class loader for the test and is coincident with getSystemClassLoader(). Its parent is the ExtClassLoader which I believe is in charge of loading anything from jre/lib/ext. But I don't know how to get a reference to the RMIClassLoader in order to find out what it's parent is.
I would appreciate any info on this.
Thanks in advance,
JoeWell that was easy.
I just used the RMIClassLoader.getClassLoader(String codebase) and was able to determine the chain.
FYI: the chian is as follows:
ExtClassLoader <-- AppClassLoader <-- sun.rmi.server.LoaderHandler
Of interest, if you have a custom class loader its parent will most likely be the AppClassLoader but the rmi class loader will not chain off of your custom class loader. It does some interesting things in order for this to work. It will look for custom class loader to load interfaces but will use the RMIClassLoader to load stubs. Pretty cool.
Thanks anyway.
Joe -
Hi all,
Couple of questions. Is dynamic class loading using classloaders supported in any, if not all versions of J2ME? I guess I should ask first, what exactly does J2ME cover? I see KVM, but do watches and PDA's, set top boxes, refrigerators and so forth all run the same J2ME JVM? Or are their "less feature full" versions? I was hoping the J2ME spec would be the "lowest common denominator" to program for, but I thought I read somewhere that small devices like watches may even have a "smaller" J2ME JVM or something, less capable. So can I write code for J2ME and it will run on all small devices like cell phones, pda's, and so forth? Or is there another J2ME version, perhaps small than J2ME.
So, from what I have found so far, it appears dynamic class loading is done at startup from a DB (of sorts) as opposed to being able to dynamically find/load classes. If this is so, is there any way to support downloading and reloading new classes like you can with J2SE, such as the hot-swap feature of web servers? Does Class.forName() at least work in that you can "replace" a class with a new version, even if it is not able to have a separate classloader instance? My guess is that J2ME supports only a single classloader space, but I thought I read somewhere that Class.forName() is available. J2ME API shows it I believe, but I could be wrong.
Any help on this topic would be appreciated.
Thanks.Dynamic class loading is not available in most (if not all) J2ME profiles and configurations. Class.forName() is available (at least in the MID profile), but not to be used for dynamic class loading. It can be used when using device-specific APIs where you can try to load a class containing device specific methods (for example a class that works only on certain Nokia phones, and has methods playSound() and vibrate(), which are not available in MIDP), and if you catch a ClassNotFound exception you can load a class that doesn't use the device specific APIs and contains stubs of the methods, or you can disable certain features in you application that need those features. For an example implementation you can have a look at Nokia's Block Game example (available from their developer site - http://www.forum.nokia.com/main.html).
As for your other more general questions about different JVM's and such, you should read all about the different configurations and profiles available in J2ME (plenty of information using in the J2ME link on this site). -
Hi all,
We are experiencing a strange behaviour of the Application Class Loader. Our main issue is that if we deploy 2 applications using our code, the first application is okay, and the second application fails its loading. During the loading, we instantiate a customized InitialContextFactory (two times at all: one time per application). As a result, we have a ClassCastException in our customized InitialContext. Above a more detailed explanation of what happen. To sum up, we think that our InitialContextFactory is loaded by a master class loader, only one time for the 2 applications, and that the second application reaches the customized InitialContextFactory instantiated for the first application, so the classes loaded for the second application are not compatible.
Details:
- Each Application create a new InitialContext with the parameter "java.naming.factory.initial" equals to "com.test.CustomInitialContextFactory".
- In the class com.test.CustomInitialContextFactory we access to other code from our application, which are passed to the context factory by the environment hashtable. In the method public javax.naming.Context getInitialContext(java.util.Hashtable env), we get some parameters from the env parameter like that: CustomObject o = (CustomObject)env.get("com.test.customObject");
When the first application launches, it works very well.
When the second application launches, it fails with a ClassCastException on the class com.test.CustomObject. We think that the class com.test.CustomObject is not loaded by the good class loader so it throws a ClassCastException.
Thank you for your helpWe have found how the JNDI layer builds the specified context factory:
ClassLoader cl = (ClassLoader) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
return Thread.currentThread().getContextClassLoader();
But OC4J has specific Thread ClassLoader: this is the cause of all our problem. So there is a solution: create a specific context factory which calls the good class loader to load the context factory.
Bye -
Need help with setting the entry point for application
Hi there,
I am kinda new to creating JAR files for application. I checked out the tutorials for creating the jar files, and I understood most of the concepts. There is one part in the tutorial which I still don't understand
it says:
We want to execute the main method in the class MyClass in the package MyPackage when we run the JAR file.
We first create a text file named Manifest.txt with the following contents:
Main-Class: MyPackage.MyClass
I am not exactly sure what the package is. Is it the name of the jar file, which I wish to create? Your detailed explanation would certainly be helpful. Thank you in advance.
Regards,
YoungHi there,
I am kinda new to creating JAR files for
for application. I checked out the tutorials for
creating the jar files, and I understood most of the
concepts. There is one part in the tutorial which I
still don't understand
it says:
We want to execute the main method in the class
s MyClass in the package MyPackage when we run the
JAR file.
We first create a text file named Manifest.txt with
the following contents:
Main-Class: MyPackage.MyClass
I am not exactly sure what the package is. Is it
it the name of the jar file, which I wish to create?
Your detailed explanation would certainly be helpful.
Thank you in advance.
Regards,
YoungIts just the package name in your code hierarchy.
http://jarticles.com/package/package_eng.html -
ConversionManager - Override and Class Loader Issues
Hi
We are using Toplink 10.1.3 deployed withiin 10gAS 10.1.3.
We have overridden the ConversionManger as documented in tips.
1. MyConversionManager extends ConversionManager.
2. We have overriden convertObject
3. We have a pre-login SessionEventAdapter that sets the ConversionManager.
We have had issues of classloading within the application previously, particularly where we have two versions of our application deployed on the same App Server instance (potentially with differing versions of MyConversionManager).
For this reason we only set the ConversionManager within the preLogin event on the Session as follows:
*//Just set the conversion manager for the session.*
event.getSession().getLogin().getPlatform().setConversionManager(getConversionManager());
We no longer set the default conversion manager, as my understanding was that this would set it at the root level within the OC4J instance (meaning that each deployment would override the previous).
Additionally, we have had to sepcify the class loader to use, within the ovverriden convertObject method, as otherwise start up of Toplink falied, as it was unable to solve references to application classes specified within class indicator mappings. We do this as follows:
*@Override*
*public Object convertObject(final Object source, final Class javaClass) {*
super.setShouldUseClassLoaderFromCurrentThread(true);
The only know issue with this, is that if I try and use OEM to veiw the Toplink Cache, I just get and AnnotatedClassNotFoundException as it is attempting to use the system class loader (that does not contain our Application classes).
Two questions therefore:
1. Is the deployment we have now stable, i.e. overriding the class loader within the overriden Conversion Manager, and only loading this against the session??
2. How can I get mutiple versions of the application to still work, together with being able to view the Toplink Cache from within OE:M.
Any help or insight, would be greatly appreciated.
MarcLooks fine, you may also wish to investigate using Converters in your mappings instead of customizing the ConversionManager.
For the OEM issue, try setting the class loader to be your application class loader instead of the thread one, i.e. MyAppClass.getLoader().
James : http://www.eclipselink.org
Maybe you are looking for
-
Problem in getting default value for Basic Pay
Hi gurus, i have created a new structure in fresh new sap server for payroll. after completing configration. when i hire an employee system , it gives an error on info 8. It did not pick the value from t510 table. please response it is urgent. Nawaz
-
How i can give date in each input for applying the exchange rate in Query.
Hi Gurus, We have a requirement to create some currency conversion queries. In the selection screen user should be able to give four inputs. Like given below Input 1. a) key figures b) Fiscal Year
-
How do I get my sbcglobal email on my new iPad?
I am having problems getting my iPad to sync with my sbcglobal email.? Any tips? Thanks
-
Understanding open syscall on FIFO with dtrace
Hi all, I'm trying to understand open syscall behaviour with respect to FIFOs using dtrace. We have a very intermittent failure with FIFOs, when writer process fails in opening pipe, but reader succeeds. I tried debugging with dtrace and found some w
-
Can i update my labview 2010 to 2013????? How ? plz help me. . . i need to install Electrical power suite 2013/2012 . it requires 2013/2012 version of labview . .i have labview 2010 installed on my PC . Please help me . How can i update my Labview