Java: Add Class to Jar archive at runtime

后端 未结 2 628
悲&欢浪女
悲&欢浪女 2021-01-14 13:14

I want to add some compiled classes (.class files) to directories(packages) in current Jar file at runtime
How can I do that?

Thanks

2条回答
  •  心在旅途
    2021-01-14 13:34

    I'm not quite sure but I don't think it's possible to load classes from a JAR file (let's call it foo.jar), then modify the very same JAR file from which the classes were loaded, add a new class and expect the class to be found by the ClassLoader.

    I'd think about refactoring the application itself and make it able to load classes dynamically (using URLClassLoader or any other technique) than trying to force the single JAR behaviour you described.

提交回复
热议问题