classloader

How can you protect/encrypt your Java classes?

坚强是说给别人听的谎言 提交于 2019-11-26 16:57:30
问题 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

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

强颜欢笑 提交于 2019-11-26 16:53:33
问题 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

URLClassLoader and accessibility of package-private methods

陌路散爱 提交于 2019-11-26 16:50:31
问题 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

how to set java class loader PARENT_LAST

不想你离开。 提交于 2019-11-26 16:09:13
问题 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

Order of loading jar files from lib directory

被刻印的时光 ゝ 提交于 2019-11-26 16:04:08
Could anyone explain the order in which jar files are loaded from the lib directory within Tomcat? Is it alphabetically? Randomly? Or some other order? BalusC It's all described in Tomcat's ClassLoading HOW-TO . It's not necessarily in alphabetic order. If you observed that behaviour, it should absolutely not be relied upon if you intend to keep your webapp portable across servers. For example, Tomcat 6 "coincidentally" orders it, but Tomcat 8 does not. Summarized, the loading order is as follows: bootstrap/system ( JRE/lib , then server.loader ) webapp libraries ( WEB-INF/classes , then WEB

Check if class exists in Java classpath without running its static initializer?

自作多情 提交于 2019-11-26 15:48:53
问题 If I use try { Class.forName("my.package.Foo"); // it exists on the classpath } catch(ClassNotFoundException e) { // it does not exist on the classpath } the static initializer block of "Foo" is kicked off. Is there a way to determine whether a class "my.package.Foo" is on the classpath without kicking off its static initializer? 回答1: Try the forName(String name, boolean initialize, ClassLoader loader) method of Class and set the param initialize to false . JavaDoc link 来源: https:/

Static references are cleared--does Android unload classes at runtime if unused?

為{幸葍}努か 提交于 2019-11-26 15:48:23
问题 I have a question specific to how the classloading / garbage collection works in Android. We have stumbled upon this issue a few times now, and as far as I can tell, Android behaves different here from an ordinary JVM. The problem is this: We're currently trying to cut down on singleton classes in the app in favor of a single root factory singleton which sole purpose is to manage other manager classes. A top level manager if you will. This makes it easy for us to replace implementations in

How do I put all required JAR files in a library folder inside the final JAR file with Maven?

↘锁芯ラ 提交于 2019-11-26 15:47:37
I am using Maven in my standalone application, and I want to package all the dependencies in my JAR file inside a library folder, as mentioned in one of the answers here: How can I create an executable JAR with dependencies using Maven? I want my final JAR file to have a library folder that contains the dependencies as JAR files, not like what the maven-shade-plugin that puts the dependencies in the form of folders like the Maven hierarchy in the .m2 folder. Well, actually the current configuration does what I want, but I am having a problem with loading the JAR files when running the

Java security: Sandboxing plugins loaded via URLClassLoader

ぐ巨炮叔叔 提交于 2019-11-26 15:36:12
问题 Question summary: How do I modify the code below so that untrusted, dynamically-loaded code runs in a security sandbox while the rest of the application remains unrestricted? Why doesn't URLClassLoader just handle it like it says it does? EDIT: Updated to respond to Ani B. EDIT 2: Added updated PluginSecurityManager. My application has a plug-in mechanism where a third party can provide a JAR containing a class which implements a particular interface. Using URLClassLoader, I am able to load

How to get names of classes inside a jar file?

断了今生、忘了曾经 提交于 2019-11-26 15:04:57
I have a JAR file and I need to get the name of all classes inside this JAR file. How can I do that? I googled it and saw something about JarFile or Java ClassLoader but I have no idea how to do it. Unfortunately, Java doesn't provide an easy way to list classes in the "native" JRE. That leaves you with a couple of options: (a) for any given JAR file, you can list the entries inside that JAR file, find the .class files, and then determine which Java class each .class file represents; or (b) you can use a library that does this for you. Option (a): Scanning JAR files manually In this option, we