classloader

Can I set the classloader policy for WebSphere in the ibm-web-bnd.xmi file?

◇◆丶佛笑我妖孽 提交于 2019-11-26 22:58:29
问题 I have a JEE application that runs on WAS 6. It needs to have the class loader order setting to "Classes loaded with application class loader first", and the WAR class loader policy option set to "Single class loader for application". Is it possible to specify these options inside the EAR file, whether in the ibm-web-bnd.xmi file or some other file, so the admin doesn't need to change these setting manually? Since the app is deployed via an automated script, and the guy who is in charge of

Java: why code packaged into a jar file prevent external classes from accessing?

五迷三道 提交于 2019-11-26 22:27:30
问题 I have a plugin system for my Java app. I invoke an external class with the URL class loader. That part works well, both when my application is run as class files, and when my application is in JAR form. The problem that I am running into is, the plugin files can run their own independent code just fine, but they create a JPanel. When I try to add that JPanel to the JPanel that's in the main application class, I get a null pointer exception referencing the main class. (com.cpcookieman.app

How to access resource using class loader in Java 9

烈酒焚心 提交于 2019-11-26 21:45:41
问题 I have a gradle project in eclipse. Here is the structure of my project I have css resource styleclass.css in scr/main/resources/css . First I tried to access it using scene.getStylesheets().add("css/styleclass.css"); But I was getting warning resource not found. I also tried it by removing module-info.java file. But result is same. Then I tried it using String urlString = ComboBoxStyling.class.getClassLoader().getResource("css/styleclass.css").toExternalForm(); Problem is, this line works if

No suitable classloader found for grab

时光总嘲笑我的痴心妄想 提交于 2019-11-26 21:29:43
问题 I have this at the beginning of a class: @Grab(group = 'org.ccil.cowan.tagsoup', module = 'tagsoup', version = '1.2') class MyClass{... I'm trying to unit test this class, but whenever I try to run JUnit 4 tests, I get this error: Caused by: java.lang.RuntimeException: No suitable ClassLoader found for grab at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect

getSystemResourceAsStream() returns null

和自甴很熟 提交于 2019-11-26 20:59:08
问题 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 here.. public class ReadPropertyFromFile { public static Logger logger = Logger.getLogger(ReadPropertyFromFile.class); public static String readProperty(String

How do I use JDK6 ToolProvider and JavaCompiler with the context classloader?

梦想的初衷 提交于 2019-11-26 20:45:21
问题 My usage case is compiling generated source files from a java program using the ToolProvider and JavaCompiler classes provided in JDK 6. The source files contain references to classes in the context classloader (it runs in a J2EE container), but not in the system classloader. My understanding is that by default the ToolProvider will create the JavaCompiler instance with the system classloader. Is there a way to specify a classloader for JavaCompiler to use? I tried this approach, modified

Reflections library not working when used in an Eclipse plug-in

≯℡__Kan透↙ 提交于 2019-11-26 20:44:17
问题 I have developed an application using the Reflections library for querying all the classes having a particular annotation. Everything was working like a charm until I decided to create an Eclipse plug-in from my application. Then Reflections stop working. Given that my application is working fine when not part of an Eclipse plug-in, I think it should be a class-loader problem. So I added to my Reflections class the classloaders of the plug-in activator class, the context class loader, and all

How to unload an already loaded class in Java? [duplicate]

断了今生、忘了曾经 提交于 2019-11-26 20:28:11
问题 This question already has answers here : Unloading classes in java? (7 answers) Closed 3 years ago . How to unload a class from the class loader, so that I can use the recently changed class on the fly without restarting my application (hot deployment)? Is it possible to do that? 回答1: Java rebel reloads changed classes on the fly. See the jrebel website for details. I don't know that I would recommend this for a production environment though, because of performance issues. JRebel on occasion

In Java, is it possible to know whether a class has already been loaded?

自古美人都是妖i 提交于 2019-11-26 20:05:56
Is it possible to know whether a Java class has been loaded, without attempting to load it? Class.forName attempts to load the class, but I don't want this side effect. Is there another way? (I don't want to override the class loader. I'm looking for a relatively simple method.) (Thanks to Aleksi) This code: public class TestLoaded { public static void main(String[] args) throws Exception { java.lang.reflect.Method m = ClassLoader.class.getDeclaredMethod("findLoadedClass", new Class[] { String.class }); m.setAccessible(true); ClassLoader cl = ClassLoader.getSystemClassLoader(); Object test1 =

Strange behavior of Class.getResource() and ClassLoader.getResource() in executable jar

孤人 提交于 2019-11-26 20:02:40
I understand from What is the difference between Class.getResource() and ClassLoader.getResource()? and from own code, that getClass().getResource("/path/image.png") is identical to getClass().getClassLoader().getResource("path/image.png") The posting Cannot read an image in jar file shows an issue where using getClass().getClassLoader().getResource("path/image.png") in an executable jar file returns null, while getClass().getResource("/path/image.png") returns the correct URL. Since Class.getResource() delegates to ClassLoader.getResource() after removing the leading slash, I would expect