classloader

Replace content of some methods at runtime

元气小坏坏 提交于 2019-11-30 07:52:40
问题 I would like to replace the content of some methods at runtime. I know I can use javassist for this but it does not work because the classes I would like to enhance are already loaded by the system classLoader . How can I do, to replace the content of a method at runtime ? Should I try to unload the class ? How can I do that ? I saw it was possible but I could not figure out how to do it. If possible, I would like to avoid using an external lib for this, I would like to code it my-self. More

How to get classloader for a bundle in equinox?

和自甴很熟 提交于 2019-11-30 07:08:18
问题 I have read a lot of equinox code for this, but still can't figure out a non-hacky way of getting the classloader for a osgi bundle in eclipse equinox setup. Is there one? 回答1: The short answer (certainly for OSGi 4.1, not sure of 4.2) is you can't get a bundle's classloader. However the Bundle interface exposes a loadClass() method and this would allow you to write a classloader that wraps the bundle API and delegates to that loadClass() method. Or you can save some time and use Spring DM's

Java - loading annotated classes

老子叫甜甜 提交于 2019-11-30 06:03:39
I know there are incredible set of tools for loading plugin classes in java, but today an idea came to my mind. What if I have a bunch of annotated and un-annotated classes in package "org.home.junk" (annotated with annotation "@AnnotatedClass") and those classes have annotated methods with say annotation "@AnnotatedMethod". First question: can I at run-time get an array/collection of all the classes in that specific package, so that I could check which one's are annotated and create an instance of them. (I am aware however how to check if Some.class has annotations courtesy of this guide:

What can done to secure jar files besides obfuscation?

天大地大妈咪最大 提交于 2019-11-30 06:01:17
问题 I'm concerned about the security of Java executables. They offer little protection against decompilation. With tools like Java Decompiler even a kid can decompile the class files to get the original code. Apart from code obfuscation what can be done to protect a class file? Is the Encrypted Class Loader still a myth? 回答1: In a previous company we had such questions, mainly driven by management paranoia. First of all, you have to understand that absolute security is only a myth: As long as

How are object dependencies between static blocks resolved?

纵饮孤独 提交于 2019-11-30 05:42:05
I recently came across this at work. While I am not sure it is really a good idea, I don't understand how static blocks are handled by the compiler. Here is an example: Consider that you have classes A and B : public class A { public final static List<Integer> list; static { list = new ArrayList<>(); } } public class B { public final static int dependsOnA; static { dependsOnA = A.list.size(); } } And a main class that just reads B.dependsOnA . The static block in B is dependent of the one in A , since it uses the list static variable. Now, the code executes properly and no NullPointerException

Is it possible to use instanceof when passing objects between Threads?

扶醉桌前 提交于 2019-11-30 04:57:25
I've run into an issue where instanceof works, and then it doesn't. Going into details is difficult, but I think this might be the problem: Reading this: http://www.theserverside.com/news/thread.tss?thread_id=40229 (search for Thread.currentThread), it seems to imply that, even if the two objects are the same class, if you pass them between threads with different class loaders, instanceof (and isAssignableFrom) might still fail. This certainly would explain the behavior I'm having, but I was wondering if anyone could verify it? (I wish the article linked at the beginning of the discussion was

A dozer map exception related to Spring boot devtools

北慕城南 提交于 2019-11-30 04:06:35
问题 I have encountered a very strange exception, and I don't know how to find the reason. Business background: Add goods and meantime it's price list, a goods have 5 price for diff level user. In controller, first convert goodForm to goods by using dozer, then call goodsService to save goods. In goodsService after saving goods, traversal goods price list and populate goodsId to goods price, GoodsForm: @Mapping("priceList") List<GoodsPriceForm> goodsPriceFormList; Goods: List<GoodsPrice> priceList

Rails class loading skips namespaced class when another class of same name in root namespace is loaded

二次信任 提交于 2019-11-30 04:02:02
问题 I have two namespaces, each with its own controller and presenter classes: Member::DocumentsController Member::DocumentPresenter Guest::DocumentsController Guest::DocumentPresenter Both presenters inherit from ::DocumentPresenter . Controllers access their respective presenters without namespace specified, e.g.: class Guest::DocumentsController < ActionController::Base def show DocumentPresenter.new(find_document) end end This usually calls presenter within same namespace. However sometimes

Modify Executing Jar file

a 夏天 提交于 2019-11-30 03:39:43
问题 Hello Stack Overflow friends. I have a simple problem which i fear doesnt have a simple solution and i need advice as to how to proceed. I am developing a java application packaged as and executable JAR but it requires to modify some of its JAR file contents during execution. At this stage i hit a problem because some OS lock the file preventing writes to it. It is essential that the user sees an updated version of the jar file by the time the application exits allthough i can be pretty

Ensure spring bean loaded from non spring context

时间秒杀一切 提交于 2019-11-30 03:27:46
问题 I have spring application alongside (jersey 2.6 classes and ) servlets . I need to get Spring bean(s) from jersey/ non spring context, Similar question suggested to get context in a static wrapper of context public static ApplicationContext getContext() { return context; } How can I be sure the context is already loaded or not null? If I can't, how should I wait/check until it spring context is loaded? In case of calling from jersey context or calling bean from a simple HttpServlet code EDIT