简体   繁体   English

Java:分离JAR版本

[英]Java: separating JAR versions

I'm developing a Java plugin for an existing Java program. 我正在为现有Java程序开发Java插件。 The existing program uses a specific version of eclipse.uml2.* and my plugin does too. 现有程序使用特定版本的eclipse.uml2。*,而我的插件也使用。 Unfortunately I need a newer version for my plugin. 不幸的是我的插件需要更新的版本。

In order to run the plugin, I need to export it into a Jar file (with all jars packed). 为了运行插件,我需要将其导出到一个Jar文件中(所有jar都打包在一起)。 Then the program executes it. 然后程序执行它。 But somehow the new eclipse.uml2.* seem to interfere with the program -> it crashes. 但是新的eclipse.uml2。*似乎以某种方式干扰了程序->它崩溃了。

Is there a way to "separate" both versions of the jar files? 有没有办法“分离”两个版本的jar文件?

An approach will be to use a custom class loader in your application. 一种方法是在应用程序中使用自定义类加载器。 This can very easily introduce bugs that are difficult to trace, so take care. 这很容易引入难以跟踪的错误,因此请当心。

http://www.devx.com/Java/Article/31614/1954 http://www.devx.com/Java/Article/31614/1954

This is the exact problem OSGi tries to solve. 这是OSGi试图解决的确切问题。 Would it be feasible to rework the Java app to another plugin platform? 将Java应用程序重做到另一个插件平台是否可行?

This will be difficult. 这将很困难。 You conceivably try to use class loader tricks to allow both versions of the eclipse.uml.* classes to be loaded in the same JVM. 可以想象,您尝试使用类加载器技巧来允许将eclipse.uml.*类的两个版本都加载到同一JVM中。 But as far as the JVM would be concerned they would be different sets of classes, and your plugin and the base java app wouldn't be able to exchange instances. 但是就JVM而言,它们将是不同的类集,并且您的插件和基本Java应用程序将无法交换实例。

It is probably simpler (and less risky ... in terms of likelihood of success) to rebuild (and if necessary modify) either the base program or your plugin so that they both work with the same version of the eclipse.uml2.* classes. 重建(并在必要时进行修改)基本程序或您的插件可能更简单(就成功的可能性而言,风险较小),以便它们都可以与eclipse.uml2.*类的相同版本一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM