classloader

JBoss and different versions of Hibernate

冷暖自知 提交于 2019-11-28 09:17:05
We are using JBoss 4.2.3 which in turn comes with version 3.2.1.ga of Hibernate. I would like to use Hibernate 3.5.1-FINAL which supports JPA 2.0. I've been trying to make this work by putting my own hibernate jars in my WEB-INF/lib folder and creating my own classloader for my WAR in jboss-web.xml <jboss-web> <loader-repository> com.moo.foo:archive=catalog-archive </loader-repository> </jboss-web> I've also tried: <jboss-web> <class-loading java2ClassLoadingCompliance="false"> <loader-repository> com.moo.catalog:loader=catalogLoader <loader-repository-config>java2ParentDelegation=false<

Java adding to a unknown type generic list

别来无恙 提交于 2019-11-28 09:11:58
I've come into something I haven't come across before in Java and that is, I need to create a new instance of say the ArrayList class at runtime without assigning a known type then add data to the list. It sounds a bit vague so here is an example: Class<?> c = i.getClass(); Constructor<?> con = ArrayList.class.getConstructor(); ArrayList<?> al = (ArrayList<?>)con.newInstance(); al.add("something"); Now the reason I'm doing this versus just using generics is because generics are already being used heavily and the "i" variable in this example would be given to use as type "?". I would really

ClassCastException: MyFilter cannot be cast to javax.servlet.Filter

Deadly 提交于 2019-11-28 08:42:26
问题 I'm migrating an application to JBoss 7, where all dependencies were in "JBOSS_HOME/server/default/lib" (JBoss 4). I included the lib "servlet.jar" (javax.servlet. *), however, after setting a Global Module for JBoss 7 (modules.xml, standalone.xml, jboss-deployment-structure.xml in war files), libraries are loaded normally by JBoss. When JBoss 7 tries to start the filters, I get following exception: 15:09:15,222 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[

How to change default class loader in Java?

我与影子孤独终老i 提交于 2019-11-28 08:29:00
Let's say I have three classes, example.ClassA, example.ClassB, and example.ClassLoader. ClassA prints out HelloWorld and ClassB imports example.ClassA and invokes its main() method. If I do this: java -cp Example.jar -Djava.system.class.loader=example.ClassLoader example.ClassA It works and uses my class loader. However, if I do this: java -cp Example.jar -Djava.system.class.loader=example.ClassLoader example.ClassB ClassB uses my class loader, but ClassA (which was imported by ClassB) is loaded using a default class loader. Is there any way to force Java to always use my class loader (unless

Order of class loading from a .war file

假装没事ソ 提交于 2019-11-28 08:25:44
I've got a question regarding the guarantees, if any, in the following scenario (note that the question is not "How to do this in a different way?" , the question is really about class loading order in the following case (to better understand how class loading works). Here's the hypothetical scenario... There's a .war file that has the following (partial) directory structure: WEB-INF/classes/com/acme/Bunny.class . . . WEB-INF/lib/acme.jar Both Bunny.class files have import referencing other classes from acme.jar Bunny.class in WEB-INF/classes/... is the only class that has the same name/path

compiling and running user code with JavaCompiler and ClassLoader

断了今生、忘了曾经 提交于 2019-11-28 07:51:21
I am writing web app for java learning. Using which users may compile their code on my serwer + run that code. Compiling is easy with JavaCompiler: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, prepareFile(nazwa, content)); task.call(); List<String> returnErrors = new ArrayList<String>(); String tmp = new String(); for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { tmp = String.valueOf(diagnostic

WAS 6.1 java.lang.VerifyError: class loading constraint violated

家住魔仙堡 提交于 2019-11-28 07:44:29
The environment is WAS 6.1 on Linux, deploying a webapp that uses classes from xercesImpl.jar. Due to company policy restrictions, the app must be deployed with settings: Class Loader Order Classes loaded with parent class loader first -> Classes loaded with application class loader first WAR class loader policy Class loader for each WAR file in application -> Single class loader for application The WAR file contains a copy of xercesImpl.jar, the same one that was in the classpath when the app was compiled. When launching the webapp, when Spring tries to parse its configs, it throws: java.lang

scala as scripting language [duplicate]

孤街醉人 提交于 2019-11-28 07:17:28
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: “eval” in Scala I know scala is a compiled language, but I do also know that I can dynamically load classes into the jvm, and I can call the scala compiler at runtime, last but not least I do also have an awesome repl, so having scala as a scripting language should be possible. so there are some tasks I need to get to run: simple interpret: val src = """ println("Hello World") """ interpret(src) call external

analyze jar file programmatically

时光总嘲笑我的痴心妄想 提交于 2019-11-28 07:16:04
问题 I need to count the number of compiled classes, interfaces and enums in a given jar file programmatically (so I need three separate numbers). Which API would help me? (I can't use third party libraries.) I've already tried quite tricky scheme which seems not always correct. Namely, I read each ZipEntry into a byte[] and then feed the result to my custom class loader which extends standard CalssLoader and just sends this byte[] to ClassLoader.defineClass (which is protect and couldn't be

How to put custom ClassLoader to use?

萝らか妹 提交于 2019-11-28 06:47:48
Hello all and thanks for the attention! I have a problem that must both be easy and obvious, yet I am stuck. I want to deliver dynamically created Java classes to be used by a 3rd party library via a custom ClassLoader. Now my problem is: How do I set my custom ClassLoader to be used to load this classes when I do not load them directly myself? I thought when I used my ClassLoader to load a certain class, it became this class's ClassLoader, and all classes loaded from that class would be channeled through my ClassLoader. I created a custom ClassLoader, following this official tutorial: http:/