当前页面: 开发资料首页 → Netbeans 专题 → NetBeans Server-Skeleton 插件教程
摘要: NetBeans Server-Skeleton 插件教程 反馈 本教程的目的是使您轻松学习开发 NetBeans IDE 服务器插件的 初级 阶段。它提供骨干服务器插件的代码,以及从头开始创建该插件...
本教程的目的是使您轻松学习开发 NetBeans IDE 服务器插件的初级 阶段。它提供骨干服务器插件的代码,以及从头开始创建该插件的详细步骤及其每个部分的详细描述。由于这只是骨干 插件,因此,此处不涉及特定于服务器的活动(如启动和停止、部署、取消部署以及自定义)。但是,您创建和安装骨干服务器插件之后,您将有足够的功能在 Server Manager 中注册新服务器类型,并通过 New Project 向导和 Project Properties 对话框将其指定给应用程序。并且您将拥有一个工作框架,在该框架顶部您可以构建自己的 NetBeans IDE 服务器插件。
本教程将介绍以下主题:
有关使用 NetBeans 插件的详细信息,请参阅 NetBeans 网站上的 NetBeans Development Project 主页。如果有问题,请访问 NetBeans Developer FAQ 或使用本页顶部的反馈链接。
开始编写插件之前,必须确保您具备所有必要的软件。此外,您可能想在亲自构建之前使用示例。了解示例介绍在本教程的其余部分您所要做的事项。
开始之前,需要在您的计算机上安装以下软件:
采用以下步骤来安装示例:
有关详细信息,请参阅 MyInstantiatingIterator.java。
有关详细信息,请参阅 MyInstanceNode.java。
选择 Start/Stop Server 时,出现一个常规的 Server Status 对话框:
有关详细信息,请参阅 MyRegistryNodeFactory.java。
即使该插件服务器无法启动,您也可以将其指定为应用程序的目标服务器,如下一步所示。

该示例由工厂类、实现类和支持文件组成。
工厂类。 该插件使用工厂模式实例化实现类。该插件的工厂在下图中高亮显示:
按照字母顺序介绍工厂:
|
文件
|
描述
|
| MyDeploymentFactory.java | DeploymentFactory 接口的实现,它生成 DeploymentManager 接口实现的实例,如 MyDeploymentManager。 |
| MyJ2eePlatformFactory.java | J2eePlatformFactory 抽象类的实现,它生成 J2eePlatformImpl 抽象类实现的实例,如 MyJ2eePlatformImpl.java。 |
| MyOptionalFactory.java | OptionalDeploymentManagerFactory 抽象类的实现。尽管它的名称表示它是可选的,但实际上它不是。您至少需要为在 IDE 中启动、停止和注册服务器而实现其方法。因此,MyOptionalFactory 类生成 MyStartServer 和 MyInstantiatingIterator 实现类的实例。 |
| MyRegistryNodeFactory.java | RegistryNodeFactory 接口的实现。该工厂的作用是生成一个或多个注册表节点(在本例中为 MyInstanceNode)作为 Runtime 窗口中的用户界面表示。 |
实现类。 实现类由工厂实例化。该插件的实现类在下图中高亮显示:
按照字母顺序介绍实现类:
|
文件
|
描述
|
| MyDeploymentManager.java | DeploymentManager 接口的虚拟实现,它不执行任何操作,由您决定提供其特定于服务器的实现。 |
| MyDeploymentPlanSplitter.java | DeploymentPlanSplitter 的实现,它允许您通过 writeDeploymentPlanFiles() 和 readDeploymentPlanFiles() 方法从多个文件还原 DeploymentConfiguration 并将其存储到多个文件。 |
| MyInstantiatingIterator.java | 创建一个向导,用于在 IDE 中注册新服务器类型实例。当前实现让用户仅指定 Display Name;对其他属性进行硬编码以便使实现尽可能简单。 |
| MyJ2eePlatformImpl.java | J2eePlatformImpl 的实现,它用于描述构建 J2EE 应用程序并随后将其部署到的目标环境。它提供一组服务器库、支持的模块类型和 J2EE 规范版本。 |
| MyStartServer.java | StartServer 抽象类的实现。它的目的是提供启动、停止以及确定服务器状态的能力。 |
| MyInstanceNode.java | 代表 Runtime 窗口中的新服务器。j2eeserver 模块,但是向每个节点添加了一组默认的功能,如显示运行状态和默认菜单项组的功能。 |
支持资源。 该插件的支持资源在下图中高亮显示:
下面按照字母顺序介绍 Java 包中的支持资源:
|
文件
|
描述
|
| Bundle.properties | 这是标准 Java 属性文件,它使用语法 Key=Value。键是出现在源代码中内容的代码名称,它的值表示将向用户显示的内容。该文件对于本地化特别有用。例如,通过创建 Bundle_ja.properties 之类的属性文件并用日语填写所有值,该插件在用户以日语模式运行 IDE 时将自动用日语显示所有内容。 |
| layer.xml | 在 NetBeans 文件系统中注册新服务器类型。 |
| nbdep.xml | 指定将在 Runtime 窗口中使用的图标、用于获得断开的 DeploymentManager 实例的 URL、指定支持的部署种类的 container-limitation element 以及上下文路径。 |
| server.gif | IDE 中新服务器类型的节点的图标。 |
有关每个 Important Files 的基本信息,请参阅 NetBeans 插件的快速入门指南。
开始编写插件前,必须确保正确地设置了项目。NetBeans IDE Dev 提供一个向导,用于设置插件所需的所有基本文件。
IDE 创建 My Server Plugin 项目。该项目包含所有资源和项目元数据,如该项目的 Ant 构建脚本。该项目在 IDE 中打开。您可以在 Projects 窗口 (Ctrl-1) 中查看其逻辑结构,在 Files 窗口 (Ctrl-2) 中查看其文件结构。例如,现在 Projects 窗口应该如下所示:
有关以上每个文件的基本信息,请参阅 NetBeans 插件模块的快速入门指南。
您需要将几个属于 NetBeans API 的类设为子类。每个类都将被声明为插件依存关系。使用 Project Properties 对话框来执行此操作。
实现类由工厂实现。在本部分中您将创建并检查它们:
MyDeploymentFactory 类是 DeploymentFactory 的实现,它生成 MyDeploymentManager 实现类的实例。
以下是该类中需要注意的方法:
新服务器实例将使用 deployer:myserver 前缀,以便用来获得连接的部署管理器的 URL 如下:deployer:myserver:localhost:8080。
执行以下操作以创建 MyDeploymentFactory 类:
package org.netbeans.modules.j2ee.myserver;
import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
import javax.enterprise.deploy.spi.DeploymentManager;
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
import javax.enterprise.deploy.spi.factories.DeploymentFactory;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
public class MyDeploymentFactory implements DeploymentFactory {
public static final String URI_PREFIX = "deployer:myserver"; // NOI18N
private static DeploymentFactory instance;
public static synchronized DeploymentFactory create() {
if (instance == null) {
instance = new MyDeploymentFactory();
DeploymentFactoryManager.getInstance().registerDeploymentFactory(instance);
}
return instance;
}
public boolean handlesURI(String uri) {
return uri != null && uri.startsWith(URI_PREFIX);
}
public DeploymentManager getDeploymentManager(String uri, String uname, String passwd) throws DeploymentManagerCreationException {
if (!handlesURI(uri)) {
throw new DeploymentManagerCreationException("Invalid URI:" + uri); // NOI18N
}
return new MyDeploymentManager();
}
public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException {
if (!handlesURI(uri)) {
throw new DeploymentManagerCreationException("Invalid URI:" + uri); // NOI18N
}
return new MyDeploymentManager();
}
public String getProductVersion() {
return "0.1"; // NOI18N
}
public String getDisplayName() {
return NbBundle.getMessage(MyDeploymentFactory.class, "TXT_DisplayName"); // NOI18N
}
}
MyJ2eePlatformFactory 类是 J2eePlatformFactory 类的实现。该实现非常简单,它生成 MyJ2eePlatformImpl 类的实例。
执行以下操作以创建 MyJ2eePlatformFactory 类:
package org.netbeans.modules.j2ee.myserver;
import javax.enterprise.deploy.spi.DeploymentManager;
import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformFactory;
import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformImpl;
public class MyJ2eePlatformFactory extends J2eePlatformFactory {
public J2eePlatformImpl getJ2eePlatformImpl(DeploymentManager dm) {
return new MyJ2eePlatformImpl();
}
}
MyOptionalFactory 类是 OptionalDeploymentManagerFactory 的实现。尽管它的名称可能暗示它是可选的,但是该工厂类不是 可选的。至少需要实现两种方法:
此处不实现其他两种方法:
执行以下操作创建 MyOptionalFactory 类:
package org.netbeans.modules.j2ee.myserver;
import javax.enterprise.deploy.spi.DeploymentManager;
import org.netbeans.modules.j2ee.deployment.plugins.api.FindJSPServlet;
import org.netbeans.modules.j2ee.deployment.plugins.api.IncrementalDeployment;
import org.netbeans.modules.j2ee.deployment.plugins.api.OptionalDeploymentManagerFactory;
import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer;
import org.openide.WizardDescriptor.InstantiatingIterator;
public class MyOptionalFactory extends OptionalDeploymentManagerFactory {
public StartServer getStartServer(DeploymentManager dm) {
return new MyStartServer();
}
public IncrementalDeployment getIncrementalDeployment(DeploymentManager dm) {
return null;
}
public FindJSPServlet getFindJSPServlet(DeploymentManager dm) {
return null;
}
public InstantiatingIterator getAddInstanceIterator() {
return new MyInstantiatingIterator();
}
}
MyRegistryNodeFactory 类是 RegistryNodeFactory 的实现。该工厂的作用是生成服务器和目标节点,它们用作 Runtime 窗口中的用户界面表示。由于新的服务器类型只有一个目标,因此它的 Admin Server 也是目标服务器,您不需要实现目标节点。
package org.netbeans.modules.j2ee.myserver.nodes;
import org.netbeans.modules.j2ee.deployment.plugins.api.RegistryNodeFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
public class MyRegistryNodeFactory implements RegistryNodeFactory {
public Node getTargetNode(Lookup lookup) {
return null;
}
public Node getManagerNode(Lookup lookup) {
return new MyInstanceNode(lookup);
}
}
实现类由工厂实现。在本部分中您将创建并检查它们:
DeploymentManager 接口的虚拟实现,它不执行任何操作,由您决定提供其特定于服务器的实现。
package org.netbeans.modules.j2ee.myserver;
import java.io.File;
import java.io.InputStream;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.shared.DConfigBeanVersionType;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
import javax.enterprise.deploy.spi.DeploymentManager;
import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException;
import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
import javax.enterprise.deploy.spi.exceptions.TargetException;
import javax.enterprise.deploy.spi.status.ProgressObject;
public class MyDeploymentManager implements DeploymentManager {
public ProgressObject distribute(Target[] target, File file, File file2)
throws IllegalStateException {
return null;
}
public DeploymentConfiguration createConfiguration(DeployableObject deployableObject)
throws InvalidModuleException {
return null;
}
public ProgressObject redeploy(TargetModuleID[] targetModuleID, InputStream inputStream, InputStream inputStream2)
throws UnsupportedOperationException, IllegalStateException {
return null;
}
public ProgressObject distribute(Target[] target, InputStream inputStream, InputStream inputStream2)
throws IllegalStateException {
return null;
}
public ProgressObject undeploy(TargetModuleID[] targetModuleID) throws IllegalStateException {
return null;
}
public ProgressObject stop(TargetModuleID[] targetModuleID) throws IllegalStateException {
return null;
}
public ProgressObject start(TargetModuleID[] targetModuleID) throws IllegalStateException {
return null;
}
public void setLocale(java.util.Locale locale) throws UnsupportedOperationException {
}
public boolean isLocaleSupported(java.util.Locale locale) {
return false;
}
public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target)
throws TargetException, IllegalStateException {
return null;
}
public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target)
throws TargetException, IllegalStateException {
return null;
}
public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] target)
throws TargetException, IllegalStateException {
return null;
}
public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2)
throws UnsupportedOperationException, IllegalStateException {
return null;
}
public void setDConfigBeanVersion(DConfigBeanVersionType dConfigBeanVersionType)
throws DConfigBeanVersionUnsupportedException {
}
public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType dConfigBeanVersionType) {
return false;
}
public void release() {
}
public boolean isRedeploySupported() {
return false;
}
public java.util.Locale getCurrentLocale() {
return null;
}
public DConfigBeanVersionType getDConfigBeanVersion() {
return null;
}
public java.util.Locale getDefaultLocale() {
return null;
}
public java.util.Locale[] getSupportedLocales() {
return null;
}
public Target[] getTargets() throws IllegalStateException {
return null;
}
}
原则上使用一个“deployment plan file”保存和加载 DeploymentConfiguration。但是很多服务器使用多个 文件来排序配置,如 Sun Java 系统应用程序服务器上 EJB 模块的 sun-ejb-jar.xml 和 sun-cmp-mappings.xml。因此,MyDeploymentPlanSplitter 是 DeploymentPlanSplitter 的实现,允许我们从多个 文件还原 DeploymentConfiguration 并将其存储到多个文件。这通过方法 writeDeploymentPlanFiles() 和 readDeploymentPlanFiles() 完成。getDeploymentPlanFileNames() 方法用来为给定模块类型定义特定于服务器的配置文件。但是不赞成这种方法,配置文件的声明通过 layer.xml 完成。
package org.netbeans.modules.j2ee.myserver;
import java.io.File;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
import org.netbeans.modules.j2ee.deployment.plugins.api.DeploymentPlanSplitter;
public class MyDeploymentPlanSplitter implements DeploymentPlanSplitter {
public void writeDeploymentPlanFiles(DeploymentConfiguration config, DeployableObject module, File[] files) throws ConfigurationException {
}
public void readDeploymentPlanFiles(DeploymentConfiguration config, DeployableObject module, File[] files) throws ConfigurationException {
}
public String[] getDeploymentPlanFileNames(ModuleType type) {
return new String[0];
}
}
MyInstantiatingIterator 类用来创建在 IDE 中注册新服务器的向导。当前实现让您仅指定显示名称;对其他属性进行硬编码以便使实现尽可能简单。
注意在 instantiate() 方法中使用的 URL 变量。它传递给 InstanceProperties.createInstanceProperties() 方法,该方法进行实际的服务器注册。URL 参数与 DeploymenManager 使用的参数相同。用这种方法我们确保服务器控制新创建的服务器实例。
package org.netbeans.modules.j2ee.myserver;
import java.awt.Component;
import java.awt.Label;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JPanel;
import javax.swing.event.ChangeListener;
import org.openide.WizardDescriptor;
import org.openide.WizardDescriptor.Panel;
import org.openide.util.HelpCtx;
import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
public class MyInstantiatingIterator implements WizardDescriptor.InstantiatingIterator {
private final static String PROP_DISPLAY_NAME = "ServInstWizard_displayName"; // NOI18N
private InstallPanel panel;
private WizardDescriptor wizard;
public void removeChangeListener(ChangeListener l) {
}
public void addChangeListener(ChangeListener l) {
}
public void uninitialize(WizardDescriptor wizard) {
}
public void initialize(WizardDescriptor wizard) {
this.wizard = wizard;
}
public void previousPanel() {
}
public void nextPanel() {
}
public String name() {
return NbBundle.getMessage(MyInstantiatingIterator.class, "MSG_InstallerName");
}
public Set instantiate() throws IOException {
Set result = new HashSet();
String displayName = getDisplayName();
String url = "deployer:myserver:localhost:8080"; // NOI18N
String username = "username"; // NOI18N
String password = "password"; // NOI18N
try {
InstanceProperties ip = InstanceProperties.createInstanceProperties(
url, username, password, displayName);
result.add(ip);
} catch (Exception ex) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
NbBundle.getMessage(MyInstantiatingIterator.class, "MSG_CreateFailed", displayName),
NotifyDescriptor.ERROR_MESSAGE));
}
return result;
}
public boolean hasPrevious() {
return false;
}
public boolean hasNext() {
return false;
}
public Panel current() {
if (panel == null) {
panel = new InstallPanel();
}
return panel;
}
private String getDisplayName() {
return (String)wizard.getProperty(PROP_DISPLAY_NAME);
}
private static class InstallPanel implements WizardDescriptor.Panel {
public void removeChangeListener(ChangeListener l) {
}
public void addChangeListener(ChangeListener l) {
}
public void storeSettings(Object settings) {
}
public void readSettings(Object settings) {
}
public boolean isValid() {
return true;
}
public HelpCtx getHelp() {
return HelpCtx.DEFAULT_HELP;
}
public Component getComponent() {
JPanel panel = new JPanel();
panel.add(new Label("< Put your installation form implementation here! >")); // NOI18N
return panel;
}
}
}
MyJ2eePlatformImpl 类是 J2eePlatformImpl 的实现,它用于描述构建 J2EE 应用程序并随后将其部署到的目标环境。它提供一组服务器库、支持的模块类型和 J2EE 规范版本。
注意:由于 MyJ2eePlatformImpl.java 的当前实现不提供 J2EE API 库,您的 Web 或 EJB 项目将不会编译,除非您在 Project Properties 对话框的 Libraries 面板中显式提供这些库。
package org.netbeans.modules.j2ee.myserver;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformImpl;
import org.netbeans.spi.project.libraries.LibraryImplementation;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
public class MyJ2eePlatformImpl extends J2eePlatformImpl {
public boolean isToolSupported(String toolName) {
return false;
}
public File[] getToolClasspathEntries(String toolName) {
return new File[0];
}
public Set getSupportedSpecVersions() {
Set result = new HashSet();
result.add(J2eeModule.J2EE_14);
return result;
}
public java.util.Set getSupportedModuleTypes() {
Set result = new HashSet();
result.add(J2eeModule.EAR);
result.add(J2eeModule.WAR);
result.add(J2eeModule.EJB);
return result;
}
public java.io.File[] getPlatformRoots() {
return new File[0];
}
public LibraryImplementation[] getLibraries() {
return new LibraryImplementation[0];
}
public java.awt.Image getIcon() {
return Utilities.loadImage("org/netbeans/modules/j2ee/myserver/resources/server.gif"); // NOI18N
}
public String getDisplayName() {
return NbBundle.getMessage(MyJ2eePlatformImpl.class, "MSG_MyServerPlatform");
}
}
MyStartServer 类是 StartServer 接口的实现。它的目的是提供启动、停止以及确定服务器状态的能力。当前实现内容是服务器始终停止并且不能启动。由您决定为使用的服务器完成特定于服务器的实现。
package org.netbeans.modules.j2ee.myserver;
import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.status.ProgressObject;
import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo;
import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer;
public class MyStartServer extends StartServer {
public ProgressObject startDebugging(Target target) {
return null;
}
public boolean isDebuggable(Target target) {
return false;
}
public boolean isAlsoTargetServer(Target target) {
return true;
}
public ServerDebugInfo getDebugInfo(Target target) {
return null;
}
public boolean supportsStartDeploymentManager() {
return false;
}
public ProgressObject stopDeploymentManager() {
return null;
}
public ProgressObject startDeploymentManager() {
return null;
}
public boolean needsStartForTargetList() {
return false;
}
public boolean needsStartForConfigure() {
return false;
}
public boolean needsStartForAdminConfig() {
return false;
}
public boolean isRunning() {
return false;
}
}
MyInstanceNode 类代表 Runtime 窗口中作为节点的新服务器类型的实例。向该节点添加一组默认的功能,这些功能显示服务器的状态并提供默认的菜单项,如 Start/Stop Server...、Refresh 和 Remove。该操作由位于该插件提供的节点顶部的标准过滤器节点来完成。MyInstanceNode 类定义在 Tools 菜单的 Server Manager 中显示的虚拟自定义实现。
package org.netbeans.modules.j2ee.myserver.nodes;
import java.awt.Component;
import java.awt.Label;
import javax.swing.JPanel;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
public class MyInstanceNode extends AbstractNode implements Node.Cookie {
private static String ICON_BASE = "org/netbeans/modules/j2ee/myserver/resources/server.gif"; // NOI18N
public MyInstanceNode(Lookup lookup) {
super(new Children.Array());
getCookieSet().add(this);
setIconBaseWithExtension(ICON_BASE);
}
public String getDisplayName() {
return NbBundle.getMessage(MyInstanceNode.class, "TXT_MyInstanceNode");
}
public javax.swing.Action[] getActions(boolean context) {
return new javax.swing.Action[]{};
}
public boolean hasCustomizer() {
return true;
}
public Component getCustomizer() {
JPanel panel = new JPanel();
panel.add(new Label("< Put your customizer implementation here! >")); // NOI18N
return panel;
}
}
已经对主文件进行编码之后,必须在 layer.xml 文件和 nbdep.xml 文件中注册您的插件。您还必须使用 Bundle.properties 文件定义希望向用户显示的标签和文本。
<folder name="J2EE">
<folder name="DeploymentPlugins">
<folder name="MyServer">
<file name="Descriptor" url="nbdep.xml"/>
<file name="Factory.instance">
<attr name="instanceCreate" methodvalue="org.netbeans.modules.j2ee.myserver.MyDeploymentFactory.create"/>
<attr name="instanceClass" stringvalue="org.netbeans.modules.j2ee.myserver.MyDeploymentFactory"/>
<attr name="instanceOf" stringvalue="javax.enterprise.deploy.spi.factories.DeploymentFactory"/>
</file>
<file name="RegistryNodeFactory.instance">
<attr name="instanceClass" stringvalue="org.netbeans.modules.j2ee.myserver.nodes.MyRegistryNodeFactory"/>
<attr name="instanceOf" stringvalue="org.netbeans.modules.j2ee.deployment.plugins.api.RegistryNodeFactory"/>
</file>
<file name="ConfigurationSupport.instance">
<attr name="instanceClass" stringvalue="org.netbeans.modules.j2ee.myserver.MyConfigurationSupport"/>
<attr name="instanceOf" stringvalue="org.netbeans.modules.j2ee.deployment.plugins.api.ConfigurationSupport"/>
</file>
<file name="J2eePlatformFactory.instance">
<attr name="instanceCreate" newvalue="org.netbeans.modules.j2ee.myserver.MyJ2eePlatformFactory"/>
<attr name="instanceClass" stringvalue="org.netbeans.modules.j2ee.myserver.MyJ2eePlatformFactory"/>
<attr name="instanceOf" stringvalue="org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformFactory"/>
</file>
<file name="OptionalFactory.instance">
<attr name="instanceCreate" newvalue="org.netbeans.modules.j2ee.myserver.MyOptionalFactory"/>
<attr name="instanceClass" stringvalue="org.netbeans.modules.j2ee.myserver.MyOptionalFactory"/>
<attr name="instanceOf" stringvalue="org.netbeans.modules.j2ee.deployment.plugins.api.OptionalDeploymentManagerFactory"/>
</file>
<file name="DeploymentPlanSplitter.instance">
<attr name="instanceCreate" newvalue="org.netbeans.modules.j2ee.myserver.MyDeploymentPlanSplitter"/>
<attr name="instanceClass" stringvalue="org.netbeans.modules.j2ee.myserver.MyDeploymentPlanSplitter"/>
<attr name="instanceOf" stringvalue="org.netbeans.modules.j2ee.deployment.plugins.api.DeploymentPlanSplitter"/>
</file>
</folder>
</folder>
<folder name="DeploymentFileNames">
<folder name="WAR">
<file name="META-INF/myserver-web.xml"/>
</folder>
</folder>
</folder>
<netbeans-deployment>
<icon>org/netbeans/modules/j2ee/myserver/resources/server</icon>
<disconnected-string>deployer:myserver</disconnected-string>
<container-limitation>
<ear-deploy/>
<war-deploy/>
<ejbjar-deploy/>
</container-limitation>
<web-context-root>
<xpath>/</xpath>
<prop-name>contextRoot</prop-name>
</web-context-root>
</netbeans-deployment>使用 Bundle.properties 文件本地化插件。Bundle.properties 为包中其他文件提供的用户界面提供特定于语言的字符串。当您使用 New Project 向导创建插件时,IDE 在 org.netbeans.modules.j2ee.myserver.resources 包中创建 Bundle.properties 文件。现在您将 key=value 对添加到 IDE 生成的 Bundle.properties 文件中并为其他包创建两个附加的 Bundle.properties 文件。
OpenIDE-Module-Name=My Server Plugin OpenIDE-Module-Display-Category=Database OpenIDE-Module-Short-Description=My Server Plugin OpenIDE-Module-Long-Description=My Server Plugin
TXT_DisplayName=My Server
MSG_InstallerName=My Server Installer
MSG_CreateFailed=Cannot create {0} server instance.
MSG_MyServerPlatform=My Server Platform
TXT_MyInstanceNode=My Server Instance TXT_MyTargetNode=My Target Instance
确保您在 org.netbeans.modules.j2ee.myserver.resources 包中具有名为 server.gif 的 16x16 图标。例如,您可以在 NetBeans IDE Dev 安装目录中的以下位置找到一些 16x16 像素图标:
enterprise1\jakarta-tomcat-5.5.7\server\webapps\admin\images
IDE 使用 Ant 构建脚本来构建和安装您的插件模块。构建脚本是在您创建 Plug-in 项目时为您创建的。
插件即在目标 IDE 或 Platform 中构建和安装。打开目标 IDE 或 Platform 以便您可以试用新插件。默认目标 IDE 或 Platform 是由开发 IDE 的当前实例使用的安装平台。注意到当您运行插件时,您将使用临时测试用户目录,而不是开发 IDE 的用户目录。
添加特定于服务器的代码之前,看一看其他人如何完成该操作。
注意上图,选中的文件就是本教程中要讨论的文件。
有关创建和开发 NetBeans 插件的更多信息,请参见以下资源:
|
版本
|
日期
|
更改
|
| 1 | 2005 年 6 月 25 日 | 初始版本 |
| 事件编号 | 描述 | 状态 |
| 1 | 代码和教程本身需要检查。需要在多个平台上测试代码。(在 Windows XP 上创建的,尚未在其他平台上测试。尽量避免由避免名称中的空格引起的潜在问题等等)。 | 有待解决。 |
| 2 | 阶段 III 和阶段 IV 完成之后,需要更新教程。 | 有待解决。 |
| 3 | 本教程中使用的一些 API 拥有已废弃的方法。这将在 Output 窗口中产生错误,但是不应该影响模块的功能。 | 有待解决。 |
| 4 | JSR 88 有助于理解该插件。但是本教程中尚未提及该 JSR。 | 有待解决。 |
| 5 | 尽管大多数链接已经使用,但是 Javadoc 链接还没有向该插件中使用的所有类和方法提供。 | 有待解决。 |