如何从另一个eclipse插件项目中调用jar中的方法? [英] How can I call a method in jar from another eclipse plugin project?

查看:645
本文介绍了如何从另一个eclipse插件项目中调用jar中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个依赖于项目的eclipse插件项目的jar中调用一个方法。但是eclipse无法解析jar中的类名。

I want to call a method in jar from another eclipse plugin project that has dependent to the project. But eclipse can't resolve the classname in jar.

我创建了 com.plugin.main com.plugin.sub 项目。


  • 将poi-ooxml-xxx.jar添加到 com.plugin.sub 项目中,并通过首选项对话框添加了构建路径。

  • com.plugin.sub项目中,将jar中的所有软件包作为导出的软件包添加到MANIFEST.MF。
  • 已添加 com.plugin.sub 根据需要插件到com.plugin.main项目中的MANIFEST.MF。

  • Added poi-ooxml-xxx.jar into com.plugin.sub project and added the buildpath through preference dialog.
  • Added all packages in jar as exported packages to MANIFEST.MF in com.plugin.sub project.
  • Added com.plugin.sub as required plugin to MANIFEST.MF in com.plugin.main project.

但是,eclipse无法解析来自com.plugin.main.actions.SampleAction的jar WorkbookFactory 中的类名。为什么?

But eclipse can't resolve the classname in jar WorkbookFactory from com.plugin.main.actions.SampleAction. Why?


  • eclipse 3.6(Helios)

  • JavaSE-1.7。

  • WorkbookFactory 的FQCN是 org.apache.poi.ss.user.model .WorkbookFactory

  • eclipse 3.6(Helios)
  • JavaSE-1.7.
  • WorkbookFactory's FQCN is org.apache.poi.ss.user.model.WorkbookFactory.

MANIFEST.MF in com.plugin.main

MANIFEST.MF in com.plugin.main:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Main
Bundle-SymbolicName: com.plugin.main; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.plugin.main.Activator
Bundle-Vendor: PLUGIN
Require-Bundle: com.plugin.sub;visibility:=reexport,
 org.eclipse.ui,
 org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy

MANIFEST.MF in com.plugin.sub

MANIFEST.MF in com.plugin.sub:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Sub
Bundle-SymbolicName: com.plugin.sub
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.plugin.sub.Activator
Bundle-Vendor: PLUGIN
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.apache.poi.ss.usermodel
Bundle-ClassPath: poi-ooxml-3.8-beta3-20110606.jar,
 .

build.properties在 com.plugin.sub

build.properties in com.plugin.sub:

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               poi-ooxml-3.8-beta3-20110606.jar


推荐答案

将jar添加到项目的错误方式



您可以通过在首选项对话框的库选项卡中添加JAR 按钮。

然后,项目中的 .class 文件自动编辑如下:

Then, .class file in the project is edited automatically as follows:

<classpath>
    ...
    <classpathentry kind="lib" path="poi-ooxml-3.8-beta3-20110606.jar"/>
</classpath>

但是添加的标签应该有导出的属性如下:

But the added tag should has exported attribute as follows:

<classpath>
    ...
    <classpathentry exported="true" kind="lib" path="poi-ooxml-3.8-beta3-20110606.jar"/>
</classpath>

不会自动生成。您必须在订单和导出选项卡中添加标签。

It isn't generated automatically. You have to add the tag in Order and Export tab by hand.

在eclipse中,您不应手动编辑Java Build Path。您应该使用插件清单编辑器,因为。通过编辑器编辑数据时,会自动编辑类。还有 build.properties plugin.xml MANIFEST.MF 将被正确和自动地编辑。

In eclipse, you shouldn't edit Java Build Path manually. You should use Plug-in Manifest Editor because .class is edited automatically when you edit a data through the editor. And also build.properties, plugin.xml, MANIFEST.MF will be edited correctly and automatically.

当您将jars添加到项目中时,必须在插件清单编辑器的运行时选项卡中使用Classpath部分。当通过该部分添加jar时, classpathentry 标签与 export 属性将添加到 .class 文件。不仅如此,jar将被添加为build.properties中的二进制文件。

When you add jars to the project, you have to use Classpath section in Runtime tabs in Plug-in Manifest Editor. When add jars through the section, classpathentry tag with export attribute will be added in .class file. Not only that, the jar will be added as binary includes in build.properties.

这篇关于如何从另一个eclipse插件项目中调用jar中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆