简体   繁体   English

eclipse插件中的外部jar

[英]External jars in eclipse plug-in

I'm creating an eclipse plug-in and I'm having trouble with external jars. 我正在创建一个eclipse插件,我在使用外部jar时遇到了麻烦。 In my plug-in I start an application which requires some external jars. 在我的插件中,我启动了一个需要一些外部jar的应用程序。 What do I have to do to export them automatically with the rest of the plug-in? 如何使用插件的其余部分自动导出它们,我该怎么办?

Thanks in advance :) 提前致谢 :)

  1. Open your plugin.xml 打开你的plugin.xml
  2. Go to Runtime tab and add your JAR in the classpath section 转到“ Runtime选项卡,然后在类路径部分中添加JAR

By following the steps below, the external JARs will be included when you export your plug-in: 按照以下步骤,导出插件时将包含外部JAR:

  1. Copy the required external JAR files into a folder in your plug-in project; 将所需的外部JAR文件复制到插件项目中的文件夹中; I like to call this folder lib , but whatever works for you. 我喜欢称这个文件夹为lib ,但是对你有用。
  2. Open the build.properties in your plug-in project and check the JARs you want to include in the build in the Binary Build section on the left. 打开插件项目中的build.properties ,并在左侧的Binary Build部分中检查要包含在构建中的JAR。

This is an easy way, though it does create an additional plug-in. 这是一种简单的方法,但它确实创建了一个额外的插件。

In Eclipse: 在Eclipse中:

  • Choose New>Other , then Plug-in Development>Plug-in from existing JAR archives . Plug-in Development>Plug-in from existing JAR archives选择New>Other ,然后选择Plug-in Development>Plug-in from existing JAR archives
  • Choose the jars you want to include. 选择您要包含的罐子。
  • On the next page, configure the plug-in. 在下一页上,配置插件。
  • In your plug-in's manifest, add the new plug-in as a dependency. 在插件的清单中,添加新插件作为依赖项。
  • In your plug-in's Properties, add the new project under Java Build Path on the Projects tab. 在插件的Properties中,在Projects选项卡上的Java Build Path下添加新项目。

Edit: You may be able to combine the jars into your plug-in by instead combining both suggestions of Zsolt and user714965 below. 编辑:您可以通过,而不是结合索尔特的两项建议及以下user714965到罐子合并到您的插件。

This is what has worked for me. 这对我有用。 If they are truly external, and this is a project for your company that is not going to be in the "wild" and you control the environment, and you have them out on the file system say at /opt/java/lib/somedir/some.jar you can tell the bundle where to find them by adding them to the Bundle-ClassPath entry in the MANIFEST.MF under META-INF. 如果它们真的是外部的,这是一个适合你的公司的项目,它不会处于“狂野”状态,你可以控制环境,你可以在文件系统上找到它们,请说/ opt / java / lib / somedir /some.jar你可以通过将它们添加到META-INF下的MANIFEST.MF中的Bundle-ClassPath条目来告诉bundle在哪里找到它们。 The syntax is: Bundle-ClassPath: ., external:/opt/java/lib/somedir/some.jar, external:/opt/java/lib/someotherdir/someother.jar 语法为:Bundle-ClassPath:。,external:/opt/java/lib/somedir/some.jar,external:/opt/java/lib/someotherdir/someother.jar

Also it would be prudent to use these in your build path so that you are working with the same jars in both build and runtime environments. 此外,在构建路径中使用这些是明智的,这样您就可以在构建和运行时环境中使用相同的jar。

I have done this where the Jars are multi-purpose (such as apache-commons) on our file systems and again we control the environment. 我已经完成了这个,在我们的文件系统上Jars是多用途的(例如apache-commons),我们再一次控制环境。

Reference the following: http://www.eclipsezone.com/eclipse/forums/t51870.html 参考以下内容: http//www.eclipsezone.com/eclipse/forums/t51870.html

  1. Copy the required external JAR files into a folder in your plug-in project; 将所需的外部JAR文件复制到插件项目中的文件夹中; I like to call this folder lib, but whatever works for you. 我喜欢称这个文件夹为lib,但是对你有用。
  2. ..but as apposed to Zsolt Török (his solution did not work for me) I double-clicked on the plugin.xml, went to the build tab, at the bottom, I clicked Add JARs..., and hey presto, it showed my project, and I then navigated to lib and included the external jar, as per step 1. ..但是对于ZsoltTörök(他的解决方案对我没有用),我双击了plugin.xml,转到了构建选项卡,在底部,我点击了添加JAR ...,嘿presto,它显示我的项目,然后按照步骤1导航到lib并包含外部jar。

Andy Thomas的方法大多有效,但您还需要在新的包装器插件中导出现有插件所需的包,以便插件在运行时可以访问它们。

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

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