我要从我制作的扩展点检索一个类。我的目标是使用外部化导出插件从我的UI插件导出文件。
Export
类的B有服务。IExport
类的类。IExport
的类作为 ExportClass 属性调用ExportXML
。我的服务班Export
未能加载ExportXML
课程,我不知道为什么。我检查了依赖项,Bundle-Path,在build.properties文件中也添加了我的org.jdom依赖项。但是,我仍然不知道,因为每次我尝试启动导出时都会无法加载类错误:
org.eclipse.core.runtime.CoreException:插件C无法加载类C.ExportXML 在org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194) 在org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:176) [...] 引起:java.lang.ClassNotFoundException:C_1.0.0.qualifier找不到C.ExportXML 在org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:448) 在org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:361)
我有点无语,因为我无法找到错误发生的地方。
我用来检索插件B中的ExportXML
类的函数是:
IExport exportClass = null;
for(IConfigurationElement contribution : this.getContributions()){
if(contribution.getAttribute(Export_ExtensionPoint_Attribute_formatExtension).equals(formatExtension)){
Object o;
try {
o = contribution.createExecutableExtension(Export_ExtensionPoint_Attribute_exportClass);
if(o instanceof IExport)
exportClass = (IExport) o;
} catch (CoreException e) {
e.printStackTrace();
}
}
}
这是C plugin.xml :
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="C"
point="B">
<exportFormat
ExportClass="C.ExportXML"
formatExtension="xml"
formatName="XML">
</exportFormat>
</extension>
</plugin>
此处我的ExportXML
标题位于C:
package C;
public class ExportXML implements IExport {
...
}
注意:我在try中输入属性formatExtension,只是creatExecutableExtension方法失败。
build.properties文件:
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
icons/,\
lib/jdom-2.0.6.jar
MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: XML Export
Bundle-SymbolicName: fr.enseeiht.waldo.tools.export.xml;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: fr.enseeiht.waldo.tools.export.xml.Activator
Bundle-Vendor: Waldo
Require-Bundle: org.eclipse.core.runtime,
fr.enseeiht.waldo.tools.analyzer;bundle-version="2.0.0",
fr.enseeiht.waldo.tools.export;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
插件结构: https://i.stack.imgur.com/6EeI6.png
提前感谢您的帮助
答案 0 :(得分:0)
MANIFEST.MF中没有 package com.hiber.Controller;
import com.hiber.dao.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.HibernateException;
public class SaveServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username=request.getParameter("username");
String password =request.getParameter("password");
String email=request.getParameter("email");
String phone=request.getParameter("phone");
String city =request.getParameter("city");
System.out.println("the name is "+username+"pass is "+password+" emial is "+email +" phone is "+phone +" and city is "+city);
try
{
// System.out.println("here we go");
UserDao ud=new UserDao();
ud.addUser(username, password, email, phone, city);
RequestDispatcher rd=request.getRequestDispatcher("welcomeJSF.jsp");
rd.forward(request, response);
// response.sendRedirect("welcomeJSF.jsp");
}
catch(HibernateException e)
{
System.out.println("Error in SaveServlet "+e);
}
}
}
,这需要告诉Eclipse在哪里查找目标代码。它应该是这样的:
Bundle-ClassPath
在MANIFEST.MF编辑器中,您可以在&#39;运行时&#39; &#39; Classpath&#39;中的标签部分。