classloader

How can you protect/encrypt your Java classes?

痞子三分冷 提交于 2019-11-27 14:55:26
Some time ago, in my work I needed to protect some classes against other people to read the code. For that purpose, I created a EncryptedClassLoader, that loaded previously encrypted classes, and can load normal (not encrypted) classes as well. Working in that way was a little complicated, and testing too (compile, then encrypt, and then decrypt). Is there any free framework to do what I needed, and is easy to handle? I mean, not only obfuscate, but also encrypt the files, so none can read or debug that part of code. It would also be great that I can change the keys for encryption easily (in

How do you disable lazy class loading/initialization in Sun's JVM?

こ雲淡風輕ζ 提交于 2019-11-27 14:44:28
By default, Sun's JVM both lazily loads classes and lazily initializes (i.e. calls their <clinit> methods) them. Consider the following class, ClinitBomb , which throws an Exception during a static{} block. public class ClinitBomb { static { explode(); } private static void explode() { throw new RuntimeException("boom!"); } } Now, consider how to trigger the bomb: public class Main { public static void main(String[] args) { System.out.println("A"); try { Class.forName("ClinitBomb"); } catch (Exception e) { e.printStackTrace(System.out); } System.out.println("B"); ClinitBomb o2 = new ClinitBomb

URLClassLoader and accessibility of package-private methods

江枫思渺然 提交于 2019-11-27 14:42:16
I have a class Formula , located in package javaapplication4 , which I load with a URLClassLoader. However, when I call it from another class Test1 , located in the same package, I can't access its methods that have a default access modifier (I can access public methods). I get the following exception: java.lang.IllegalAccessException: Class javaapplication4.Test1 can not access a member of class javaapplication4.Formula with modifiers "" How can I access package-private methods of a class loaded at runtime from the same package? I suppose it is a problem with using a different class loader,

What does “When a Class is loaded” actually mean?

牧云@^-^@ 提交于 2019-11-27 14:42:13
问题 It is said that static blocks in java run only once when that class is loaded. But what does it actually mean? At which point is a class loaded by JVM (Java Virtual Machine)? Is it when the main method in that class is called? And is it that all the super-classes of the same class are also loaded when the main method starts execution? Consider that A extends B and B extends C. All have static blocks. If A has the main method, then what will be the sequence of execution of static blocks? 回答1:

Java Classloader - how to reference different versions of a jar

 ̄綄美尐妖づ 提交于 2019-11-27 14:00:17
This is a common problem. I'm using 2 libraries A.jar and B.jar and these depend on different versions of the same jar. Let's say that at runtime I need THIS.x.x.x.jar MY.jar -> A.jar -> THIS.1.0.0.jar -> B.jar -> C.jar -> THIS.5.0.0.jar I can compile the specific jar (A.jar/B.jar) against its dependency but at runtime I've to load only 1 version. Which one? Loading only 1 dependency (the latest version) means that my code will probably throw runtime exceptions if the libraries are not Backward Compatible (are there Backward Compatible libraries out there?). Anyway I know that something like

Does the Java ClassLoader load inner classes?

我是研究僧i 提交于 2019-11-27 13:38:05
问题 If I have a inner class declaration such as: Class A { public static class B { } } followed by: Class<?> implClass = getClass().getClassLoader().loadClass("A"); Will the A$B inner class be loaded as well? What if the B inner class was not declared as "static" ? 回答1: Once the code is compiled, there's no such thing as an inner class . If you look at the results of javac , you'll see two files: A.class A$B.class So class B is not loaded when A is loaded, B just happens to be defined in A . Edit

Java - loading annotated classes

十年热恋 提交于 2019-11-27 13:37:44
问题 I know there are incredible set of tools for loading plugin classes in java, but today an idea came to my mind. What if I have a bunch of annotated and un-annotated classes in package "org.home.junk" (annotated with annotation "@AnnotatedClass") and those classes have annotated methods with say annotation "@AnnotatedMethod". First question: can I at run-time get an array/collection of all the classes in that specific package, so that I could check which one's are annotated and create an

how to set java class loader PARENT_LAST

岁酱吖の 提交于 2019-11-27 12:55:26
i have a spring mvc web application that I need to change the class loader on. I need to change the class loader to be equal to PARENT_LAST. I am using WAS 6.1 and already have a jacl script from a previous web application I can copy to do the job. In the last application Apache ant was used and what they did was to make the deploy dependent on running the jacl script. In my new web application I am using maven install to create a war file and am deploying that war file to my application server. How can I set the class loader to be PARENT_LAST using maven? I know how to do it in the console

getClass().getClassLoader() is null, why?

半世苍凉 提交于 2019-11-27 12:20:35
I've got some code that calls.. x = getClass().getClassLoader(); This returns null though. When I start the same code not from Eclipse, but the command line, it returns a classloader. I can hack the code to do this... if (getClass().getClassLoader() == null) { x = ClassLoader.getSystemClassLoader().getSystemResourceAsStream( loadedPropFileName ); } both are compiled and run with the same JVM. (I'm 99.99% sure). Anyone have any ideas why the first would return null for the classloader? Edit: My question is does "Anyone have any ideas why the same class would return null when started via Eclipse

Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger

那年仲夏 提交于 2019-11-27 12:19:44
I've got an interesting problem in which the org.apache.log4j.Logger class is not found during runtime. I'm trying to get authorized and that is where it's failing: OAuthAuthorizer oauthAuthorizer = new OAuthAuthorizer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, SAML_PROVIDER_ID, userId); I'm using JDeveloper 11.1.1.6. Here is what I know: I've looked in my UI.war/WEB-INF/lib directory and I see the log4j-1.2.17.jar there. The class complaining about it is org.opensaml.xml.XMLConfigurator Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Logger at org.opensaml.xml.XMLConfigurator.