classloader

Loading two classes in different JARs

▼魔方 西西 提交于 2019-12-01 06:59:28
I got two classes with the same package in different JARs. Until the previous version, both classes were identical, so i had no issues in loading them. Now, one of them has a new method added and if I want to access it, not only should I import the class with that package, i also need to make sure the jar with the correct class comes first in the classpath. i.e. javac -classpath "%classpath%;a.jar;b.jar" MyClasses.. where a.jar has the class with my new method. Now, how do i ensure this when my app goes to production, where it's deployed as an EAR file, with all the libraries under WEB-INF/lib

Use a custom classloader at compile time

試著忘記壹切 提交于 2019-12-01 06:50:24
Is it possible to specify a custom classloader for javac (or some alternative java compiler)? I'd love such a feat because it would allow me to compile classes that use classes that are only found by my special classloader. For the curious ones: I'd write a classloder that connects to a database and creates classes based on the tables it finds. When you run javac you can specify the classloader like so: javac -J-Djava.system.class.loader=org.awesome.classloader sourcefile.java It may be possible to initialize a custom classloader and then use it while calling the new Java 6 Compiler API in

Java casting / classloader issues

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:39:09
问题 Here is the simplified version of the problem: SomeClass c = (SomeClass) obj.getSomeClassParent() not always but it happens sometimes to trigger exception org.somepackage.SomeClass can't be cast to org.somepackage.SomeClass How is this possible ? I suppose it has something to do with the fact that JAI imageio is native lib, but relay how can this happen ? I'm probably missing something but what ? I'm using JAI imageio version 1.1 dcm4che 2.0.21 DICOM lib Here is the original code

Will new instance of JVM or reflection help in this case

走远了吗. 提交于 2019-12-01 06:37:36
问题 I had a problem that I posted before but got no clear solution How to prevent JFrame from closing. So I am posting a SSCCE may be this might help in better understanding the problem being faced package myApp; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import javax.swing.JFrame; import App2.Applic2; public class MYApp { @SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String arg[]){ JFrame f = new JFrame(); f

Can a loaded JAR be deleted by the Java-Process?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 06:28:24
问题 Hello I have following Problem: Within an uninstall-process I load a JAR (jdbc-driver). URL pDriverJar = jarToDelete.toURI().toURL(); URL[] lURLList = new URL[]{pDriverJar}; URLClassLoader lLoader = new URLClassLoader(lURLList, Thread.currentThread().getContextClassLoader()); Thread.currentThread().setContextClassLoader(lLoader); Class<?> aClass = Class.forName("jdbc.Driver"); // was Oracle: oracle.jdbc.OracleDriver but should not be important if(jarToDelete.delete()){ System.out.println(

Loading resource bundles using a custom class loader

霸气de小男生 提交于 2019-12-01 06:27:05
问题 import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class JarClassLoader extends ClassLoader { private String path; public JarClassLoader(String path) { this.path = path; } @Override public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> c = findLoadedClass(name); if (c == null) { try { c = findSystemClass(name); } catch

PMD rule “Use Proper Class Loader” explaination?

做~自己de王妃 提交于 2019-12-01 06:21:54
问题 There is the following PMD rule: Use Proper Class Loader (Critical) In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead. Can somewhat explain more what they are thinking of? What exactly means "J2EE" environment here? 回答1: J2EE environment refers to the Java Enterprise Edition. Here, you do not run your program as a standalone application on the JVM, but instead, you let the JEE Application Server (e.g. Glassfish or Tomcat) to run it

Converting a given class (let's say, java.lang.Object) to a byte array. Is it possible?

馋奶兔 提交于 2019-12-01 06:15:39
Given that class loaders accept to take as input a byte array of a given class, returning a Class<?> , I wonder whether it is possible to do the reverse, that is, to pass a Class<?> and get its byte array? Keep in mind that I'm not talking about serialization! You can use ClassLoader.getResourceAsInputStream() however it is not guaranteed this will be the same bytes as that which was loaded. I don't believe the actual bytes loaded are stored anywhere. No standard way I know of. But you might implement your own delegating classloader, keeping track of classes loaded in terms of name and

JIMFS not recognized by ZipFileSystemProvider

被刻印的时光 ゝ 提交于 2019-12-01 05:38:55
问题 I have a zip file created in jimfs (google in memory file system) from a byte array. When trying to open that file with ZipMemoryFileSystem , I get an error that the provider is not recognized. My code is as following: public static void test(byte[] document) { try { try (FileSystem memoryFileSystem = Jimfs.newFileSystem(Configuration.unix())) { Files.write(memoryFileSystem.getPath("/file.zip"), document); URI uri = URI.create("jar:" + memoryFileSystem.getPath("/file.zip").toUri()); Map

eclipselink PersistenceUnitLoadingEception in executable JAR

半世苍凉 提交于 2019-12-01 05:31:32
I am developing a stand-alone java application which uses eclipselink. It is all fine when I execute the app from eclipse IDE. But I've exported an executable JAR file, and since than I can not make eclipseLink work. I have found similar issue in the Eclipse community forum here , but yet not too handy: Please help, My exception is the following: 01 dec. 2010 22:47:31,199 INFO Configuration:97 - Iniciate database Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke