Java override class to Load project Class instead Jar class

徘徊边缘 提交于 2019-12-24 15:24:18

问题


I have a jar that contain a class that I would like to modify. For some reason I do not want to re-compile and update the Jar. So what I do is I recreate a full qualified name for that class in my project, and place my code in it, but I do not have an idea how to ensure JVM loaded my project class and not the Jar class. I have look through some post but they are about how to load a Jar class into project, not the other way round.


回答1:


Typically all you need to do is ensure that your class is on the classpath before the jar containing the code you're trying to override.

If you're running from the command line (replace : with ; for execution on windows):

java -cp myproject.jar:their.jar com.package.Main

If you're using Eclipse right-click on the project > Build Path > Configure Build Path..., then select the "Order and Export" tab and make sure your project source directory is above the jar you're overriding in the list.



来源:https://stackoverflow.com/questions/30770549/java-override-class-to-load-project-class-instead-jar-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!