classloader

How to use separate class loaders and run in same JVM? (OSGI)

I've read that OSGI uses separate classloaders per module which allows modules to use different versions of their dependencies.. while at the same time running all modules in the same JVM. How does this work? If module A uses version #1 of a dependency and module B uses version #2, won't you run into trouble if module A passes an inst...

How can I implement an abstract singleton class in Java?

Here is my sample abstract singleton class: public abstract class A { protected static A instance; public static A getInstance() { return instance; } //...rest of my abstract methods... } And here is the concrete implementation: public class B extends A { private B() { } static { instance = new...

Is there a way to turn on some sort of JVM logging so I can see whats happening during classloading etc.

I'm trying to optimize the startup time/class loading time of my Java web app because its on the Google App Engine and startup time is important. Is there a way I can turn on some sort of class loading debug messages or someway to see where time is being spent while class loading? I want to see if any specific libraries take a while to...

Modify Executing Jar file

Hello Stack Overflow friends. I have a simple problem which i fear doesnt have a simple solution and i need advice as to how to proceed. I am developing a java application packaged as and executable JAR but it requires to modify some of its JAR file contents during execution. At this stage i hit a problem because some OS lock the file...

How to use Blazeds with a custom classloader?

Hi, has anybody tried using a custom classloader with BlazeDS? We have a web application using BlazeDS and we can convert Java objects in to ActionScript object and back without problems in the main application. However, we also have a plug-in mechanism based on a custom classloader. BlazeDS cannot map the types contained in jar files...

Is Java class initialized by the thread which use it for the first time?

Lets assume following classes definition: public class A { public final static String SOME_VALUE; static { SOME_VALUE = "some.value"; } } public class B { private final String value = A.SOME_VALUE; } Assuming that the class A hasn't been loaded yet, what does happen when object of the class B is instantiated ...

Is there an easy way to get the Scala REPL to reload a class or package?

I almost always have a Scala REPL session or two open, which makes it very easy to give Java or Scala classes a quick test. But if I change a class and recompile it, the REPL continues with the old one loaded. Is there a way to get it to reload the class, rather than having to restart the REPL? Just to give a concrete example, suppose...

Implicity usage of Java Custom class loaders?

Hi I've written some customer class loader that load some classes from a certain directory (that is not in the classpath), say: class FileSystemClassLoader extends Classloader{ // implementation details } I have some directory say /home/mhewedy/classes/ that is not in the classpath, this directory contains some classes that I use t...

load class not in classpath dynamically in web application - without using custom classloader

I am developing a web application. The web application generates java classes on the fly. For example it generates class com.people.Customer.java In my code, I dynamically compile this to get com.people.Customer.class and store in some directory say repository/com/people/Customer.class which is not on the classpath of my application se...

How to fix this java.lang.LinkageError?

I am trying to configure a custom layout class to Log4J as described in my previous post. The class uses java.util.regex.Matcher to identify potential credit card numbers in log messages. It works perfectly in unit tests, also in a minimal web app containing a single servlet. However when I try to deploy it with our app in JBoss, I get t...

getPackage() returning null when my JUnit test is run from Ant

I'm having problems running a JUnit test. It runs fine in Eclipse, but now I'm trying to run it from the command-line using Ant. The problem is that the following code is returning null: getClass().getPackage(). I'm running my JUnit test like so: <junit fork="no" printsummary="yes" haltonfailure="no"> <classpath refid="j...

Why is the setContextClassLoader() method placed on Thread ?

Why is the setContextClassLoader() method placed on Thread? What different thread have different classloaders? The question is what if I extended a ClassLoader, loaded there some new classes. to the my custom classloader. Now , I want it to be the context classloader , so I call the method Thread.currentThread().setContextClassLoader...

Mechanism of tomcat

This is tomcat loader structure: Bootstrap | System | Common / \ Webapp1 Webapp2 ... My question is how does the loaders actually work? Do they load all classes when tomcat is started even when there is no request? Or they load necessary classes when a request comes in? And ho...

WEB-INF/lib jars not found in JBoss 4.0.2 war deploy

I have a simple web application (one jsp and one servlet) file that I've copied into jboss-4.0.2/server/default/deploy folder and it has successfully hot deployed as I can access the jsp page. However, when I invoke the servlet, I am getting a java.lan.NoClassDefFoundError. I suspect that the jars under the WEB-INF/lib directory within ...

How to add deploy.jar to classpath?

I am facing the problem: I need to add ${java.home}/lib/deploy.jar JAR file to classpath in the runtime (dynamically from java). The solution with Thread#setContextClassLoader(ClassLoader) (mentioned here) does not work because of this bug (if somebody can explain what is really a problem – you are welcome). The solution with -Xbootcla...

Classloader problems Tomcat 6 javagent

I am using Salve Dependency Injection library that instruments the byte code of the web application. I specified -javaagent in Tomcat VM options and pointed it to the Salve agent jar. The agent jar gets loaded, but then it throws a java.lang.NoClassDefFoundError unable to find classes that are in other Salve jars which are located in WE...

getSystemResourceAsStream() returns null

Hiii... I want to get the content of properties file into InputStream class object using getSystemResourceAsStream(). I have built the sample code. It works well using main() method,but when i deploy the project and run on the server, properties file path cannot obtained ... so inputstream object store null value. Sample code is h...

Running a Java daemon with a GWT front-end served by embedded Jetty

Greetings, coders, Background Info and Code I am trying to create a daemon-type program (e.g., it runs constantly, polling for things to do) that is managed by a GWT application (servlets in a WAR) which is in turn served by an embedded Jetty server (using a WebAppContext). I'm having problems making the GWT application aware of the da...

Strange jboss console error

Hello everyone, I'm creating additional module to already multi-module maven project. And for this one I want everything to be like in other modules(meaning dependencies) just to test hello world, then I'll go do some more complex stuff. And it does print hello world as it should when deployed onto jboss server, but I get some strange e...

How to use an OSGi service from a web application?

I'm trying to develop a web application that is going to be launched from a HTTP OSGi service, this application needs to use other OSGi service (db4o OSGi), for what I need a reference to a BundleContext. I have tried two different approaches to get the OSGi context in the web application: Store the BundleContext of the Activator in a ...