classloader

How can I use different JARs for compiling and testing in maven?

此生再无相见时 提交于 2019-12-10 03:36:37
问题 I compile my programm against javaee-api. But for Junit testing I must use a specific implementation like glassfish's javaee.jar to avoid errors like java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence (see also 1). So avoid using methods, that are only available in glassfish implementation, I want to compile my artifact with the general api, but run junit with the implementation jar. But both provide equal

Java/JSF/Tomcat/Spring - Proxy-Object has different methods than original object

泪湿孤枕 提交于 2019-12-10 02:48:18
问题 today I ran into this problem which really bugs me, as almost the code already worked (and stopped working even after reverting to the older version). I'm accessing a Spring-Bean on a Facelets-Page. Spring wraps these objects in Proxies to use aspects and some other stuff. The problem is, that I get an exception when trying to access the property of a bean. The exception is something like this: javax.el.PropertyNotFoundException: /customers.xhtml @23,27 value="#{customerBean.customer}":

ClassLoad an Enum type

送分小仙女□ 提交于 2019-12-10 02:39:50
问题 How would one go about instantiating an Enum type via a ClassLoader or similar mechanism? (I'm trying to keep everything under the same context classloader for a standalone server application). I have something like: ClassLoader loader = new CustomClassLoader(parent, libDir); Thread.currentThread().setContextClassLoader(loader); // trouble area Class<?> containerClass = loader.loadClass("com.somepackage.app.Name$SERVER"); I had wrongly thought simply loading the Enum would be enough to kick

How to check whether a class is initialized?

大兔子大兔子 提交于 2019-12-10 01:48:04
问题 You'll probably ask, why would I want to do that - it's because I'm using a class (from an external library) which does stuff in its static initializer and I need to know whether it's been done or not. I looked at ClassLoader , but didn't find anything that looked useful. Any ideas? 回答1: You can use the ClassLoader.findLoadedClass() method. If it returns null, then the class isn't loaded. This way you don't load the class if it wasn't already loaded. WARNING : This code doesn't really work

Is Java class loader guaranteed to not load classes that aren't used?

♀尐吖头ヾ 提交于 2019-12-10 01:30:08
问题 Is there a guarantee that (the default, system) Java class loader doesn't attempt to load classes that aren't referred to in the code being run? A couple of examples of what I mean: I'm using a framework.jar which I know to contain references to another library.jar 's classes in it, but I'm using only such part of the framework that doesn't contain those references. Is it safe to leave library.jar out? Static blocks are run when a class is first loaded. If no running code contains references

Does JVM loads all used classes when loading a particular class?

梦想与她 提交于 2019-12-09 23:37:48
问题 When JVM loads a class A, does it load all of the classes used within A? And I'm wondering if import declarations are matter somehow to the loading process? The link to JLS would be appreciated. 回答1: Import and class loading are unrelated. The former just saves typing: it allows you to use the short class name rather than the fully-resolved class name in your code. Classes are loaded by the JVM when they're used for the first time. 回答2: import merely helps the programmer. When the class file

How can i check if android device supports a library?

百般思念 提交于 2019-12-09 21:59:22
问题 I created an Android application with IR blaster and I want my code to check if an Android device supports these libraries. When another device installs my app, it crashes. How can I avoid this? I want my code to get info about whether the phone supports my app. 回答1: This is a similar problem to loading JDBC drivers. If the drivers don't exist you don't want to crash out your entire app. The basic principle of the solution is to use Class.forName() This lets you check if the class exists and

Java Applet - Cannot inherit from final class

旧城冷巷雨未停 提交于 2019-12-09 21:14:58
问题 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

Java ClassLoader and Dependency Resolution

为君一笑 提交于 2019-12-09 18:22:19
问题 Can someone clarify that the role of a ClassLoader is not only to load an individual class, but also its dependencies? And if so, what exactly does the entire process entail? I'm looking for implementation detail if at all possible. For example, at some point, bytes are going to have to be read in from somewhere (a network or filesystem location), and file system locations are going to have to be calculated on the basis of a classes canonical name and a foreknowledge of class paths available

Using JavaCompiler in an OSGi Bundle

懵懂的女人 提交于 2019-12-09 17:41:00
问题 I'm in the process of refactoring a Java application to use OSGi. One feature of the application is on-the-fly Java compilation using javax.tools.JavaCompiler . In the original application this process worked by feeding the compiler the existing classpath, like so. JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); String[] options = {"-classpath", System.getProperty("java.class.path")}; DiagnosticListener<JavaFileObject> listener = new DiagnosticListener<JavaFileObject>() {...};