classloader

getClass().getProtectionDomain().getCodeSource().getLocation().getPath() Throw a null pointer exception

≯℡__Kan透↙ 提交于 2021-02-08 08:06:36
问题 I used this line of code in a Java class to retrieve a URI which i used to customize the ClassLoader: String uri = getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); Now the same line of code in an Android App in the MainActivity to be exact throw a null pointer exception. Is there something special for Android development ? Thanks. 回答1: getProtectionDomain() is not implemented in Android's version of Java http://developer.android.com/reference/java/lang/Class.html

How to reload properties file without rebooting Tomcat

时间秒杀一切 提交于 2021-02-08 03:29:05
问题 I load a property file from classpath with the method : String cheminFichier = new StringBuilder(100).append(classeBP.getPackage().getName().replace(".", "/")).append(File.separator).append( REPERTOIRE_MAPPING).append(nomFichier).append(".properties").toString(); InputStream isMapping = Thread.currentThread().getContextClassLoader().getResourceAsStream(cheminFichier.toString()); if (isMapping == null) { throw new ServiceMappingException("Erreur lors du chargement du mapping du service. Le

load class not in classpath dynamically in web application - without using custom classloader

本秂侑毒 提交于 2021-02-07 08:13:14
问题 I am developing a web application. The web application generates java classes on the fly. For example it generates class com.people.Customer.java In my code, I dynamically compile this to get com.people.Customer.class and store in some directory say repository/com/people/Customer.class which is not on the classpath of my application server.My application server(I am using WebSphere Application Server/Apache Tomcat etc) picks up the classes from the WEB-INF/classes directory. The Classloader

Java - Load a class outside of classpath. What are the options

不打扰是莪最后的温柔 提交于 2021-02-05 07:49:23
问题 I got a Java product which is used by many clients. The product gets added as a jar into the client's (say for example XYZ company who wants to use his product for their needs) code base and works independently. Its a stand alone product and all the client projects depends (maven dependency) on this one product (which again is a couple of java projects bundled as a jar rolled out with a license) Now i am in a situation to make the engine use a class outside of it's class path. It's a client

In which scenarios the remote class loading are needed?

北战南征 提交于 2021-01-29 07:14:02
问题 Remote class loading means load classes which are not presented in the place where they are executed. For example, Java Applet needs to load classes from server to local and execute them locally. Some programs containing URLClassLoader need load classes from network, and execute locally. How about RMI? I found a class called RMIClassLoader? Is it remote class loading? 回答1: A class loader is a way to load classes of any sort: Files, network, memory, even dynamically generated ones. A

Getting a resource in a different project using classloader

夙愿已清 提交于 2021-01-28 02:26:04
问题 Using the ClassLoader#getResource(), I need to access a file that is present in a project other than the one where my current code resides. How can this be done? I'm using eclipse. Directory Structure: Root |-project1 | |-package | |-myResourceFile |-project2 |-package |-myCodeFile I'm trying to get myResourceFile from myCodeFile, using myCodeFile.class.getClassLoader().getResource("../../project1/package/myResourceFile") but its always returning null. I do not want to add project1 to the

Getting a resource in a different project using classloader

蓝咒 提交于 2021-01-27 22:51:07
问题 Using the ClassLoader#getResource(), I need to access a file that is present in a project other than the one where my current code resides. How can this be done? I'm using eclipse. Directory Structure: Root |-project1 | |-package | |-myResourceFile |-project2 |-package |-myCodeFile I'm trying to get myResourceFile from myCodeFile, using myCodeFile.class.getClassLoader().getResource("../../project1/package/myResourceFile") but its always returning null. I do not want to add project1 to the

How Does WebSphere Choose the Classloading Order in a Folder (WEB-INF/lib)

南楼画角 提交于 2021-01-27 13:22:46
问题 I am currently facing an interesting problem where our application fails to start up on 3/4 nodes due to classloading issues. The problem seems to be that WAS is loading b.jar before a.jar. After troubleshooting more, I found that all of the nodes load the jars in different orders (via Classpath viewer in console) and the working node may have just been a fluke. How does WebSphere determine the classloading order within an installed applications WEB-INF/lib folder? 回答1: Order of loading jars

Custom Java classloader and inner classes

放肆的年华 提交于 2021-01-27 12:51:29
问题 I have this method (in my own classloader) that loads classes from zip: ZipInputStream in = new ZipInputStream(new FileInputStream(zip)); ZipEntry entry; while ((entry = in.getNextEntry()) != null) { if (!entry.isDirectory()) { byte[] buffer = new byte[(int) entry.getSize()]; in.read(buffer); if (!entry.getName().endsWith(".class")) continue; String name = entry.getName().replace(".class", "").replace("/", "."); Class<?> cls = this.defineClass(name, buffer, 0, buffer.length); this

Eclipse/OSGI, Java 11, JAXB, and the Classloader

一曲冷凌霜 提交于 2021-01-07 01:21:08
问题 I have two Java modules, A and B. A provides a core model with JAXB annotations and helper classes for creating doing JAXB stuff (creating the context, marshalling, unmarshalling, etc.) B provides additional classes that are included in the model via @XmlAnyElement(lax = true) and must therefore be added to the JAXB context. This works fine in plain Java - B's classloader sees all the relevant classes and can instantiate the JAXB context with: JAXBContext.newInstance(RootFromA.class,