classloader

ClassCircularityError thrown by ClassLoader.defineClass

拥有回忆 提交于 2019-12-05 00:20:47
I'm loading classes using a custom class loader. For the most part, everything works, but sometimes when I load particularly complex projects/libraries, I get a strange bug: Exception in thread "main" java.lang.ClassCircularityError: org/apache/commons/codec/binary/Hex at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.lang.ClassLoader.defineClass(ClassLoader.java:466) at my.custom.class.Loader.loadClass(...) Looking at the Javadocs, I wouldn't expect defineClass

Tomcat Unable to create initial connections of pool

不羁岁月 提交于 2019-12-04 23:14:29
So I have a web app which I deploy / redeploy on a remote Tomcat server instance. Sometimes, the deploy and even redeploy (by redeploy I mean moving the ROOT.war through SFTP and leave Tomcat to actually redeploy it) work as expected, no issues whatsoever with the database connection. Unfortunately, other times, after redeploy, it just refuses to connect to the database, as apparently it doesn't recognize the MySQL driver anymore. The MySQL connector lib is inside Tomcat's lib folder, not package with the WAR. pom.xml: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java<

Custom Class Loader In Java [closed]

冷暖自知 提交于 2019-12-04 22:10:31
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Is it possible to make my own Custom Class Loader In java. If Yes Then Please Guide me. Instead of class obfuscation I want to change in class file so that it cant be reversed by any tool You can use some obfuscation tools, like ProGuard. A self written ClassLoader, must be placed in a standard .class file, that the JVM can load it. And then you secure loader can be reverse engineered. Don't do it by yourself.

Custom ClassLoader not garbage collected

允我心安 提交于 2019-12-04 21:57:24
In an attempt to solve this problem , I built a (very) small project that is reproducing part of it. It is a NetBeans project using Glassfish v2.1.1 and OpenJpa-1.2.2. Globally, the goal is to be able to reload dynamically some business code (called 'tasks') without the need to (re)make a full deployment (eg via asadmin). In the project there are two of them: PersonTask and AddressTask which are simply accessing some data and printing them out. In order to do that, I've implemented a custom class loader that read the binary of class files and inject it via the defineClass method. Basically,

Encrypted class files with decryption handled by a native library

喜你入骨 提交于 2019-12-04 21:16:53
The article "Cracking Java byte-code encryption" ( javaworld.com/javaworld/javaqa/2003-05/01-qa-0509-jcrypt.html ) explains why class file encryption using a custom class loader is pointless, because at some point you always need to call defineClass(), which passes the class file to the JVM as an unencrypted byte array. However I've seen solutions where a slightly different approach is used; the class is decrypted by a native library and handed over to the JVM as a java.lang.Class instance through the findClass() method -- defineClass() is never called. Does that mean that these solutions do

android dexclassloader get list of all classes

限于喜欢 提交于 2019-12-04 20:19:54
问题 I am using external jar from assets or sdcard in my android application. To do that I am using DexClassLoader. DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader()); to load a class : Class myNewClass = cl.loadClass("com.example.dex.lib.LibraryProvider"); it works really nice but now I want to get list of all classes names in my DexClassLoader I found this to work in java but there is no such thing in

How to access a resource / configuration / text file in an external Jar from Java?

人盡茶涼 提交于 2019-12-04 19:05:43
I am running a program in com.me.X.jar . In an external com.me.Y.jar , I have a configuration file located at ' config/conf.txt ' in the root of the Jar. How can I access this configuration file programmatically from within Java? com.me.Y.jar is not currently loaded in memory and is composed of just non-code resources. jar files are just zip files. So google for an example how to read a zip file. Or have a look at the API ZipInputStream The easiest option for reading embedded resources is to use Class.getResource or Class.getResourceAsStream I can think of several ways to achieve this,

Difference between loading a class and instantiating it

北城余情 提交于 2019-12-04 18:15:16
问题 Could someone explain what is the difference between Class loading and instantiating a Class. When we load a class with Static variable does it also get instantiated the same time the Class get loaded? After all static code is part of the class rather than it's individual instances. It would be helpful if someone provided an example to help me understand this better. 回答1: Here is some nice explanation(with an example and observation) When a class is loaded and initialized in JVM - Java When

Java Applet - Cannot inherit from final class

隐身守侯 提交于 2019-12-04 17:27:28
We have a java applet which is working OK in most client environments, primarily Windows 7, but recently we have been asked to support Ubuntu clients as well. The problem is that when the applet is fired up on the Ubuntu client (running Firefox and the natively installed "IcedTEA" Java VM 1.7.0_75) we get this exception: java.lang.VerifyError: Cannot inherit from final class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader

Dynamically load the JDBC driver

巧了我就是萌 提交于 2019-12-04 17:21:08
问题 I'm trying to load the JDBC driver dynamically with this kind of code: try{ URL[] url={new URL("file:libs/mysql-connector-java-5.1.21.jar")}; URLClassLoader loader = new URLClassLoader(url, System.class.getClassLoader()); loader.loadClass(drivername); Enumeration<Driver> drivers = DriverManager.getDrivers(); while(drivers.hasMoreElements()){ Driver driver = drivers.nextElement(); System.out.println("driver:"+driver); } Class.forName(drivername, true, loader); drivers = DriverManager