| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <title>Creating a NetBeans Module Using Maven</title> |
| <link rel="stylesheet" type="text/css" href="https://netbeans.org/netbeans.css"/> |
| <meta name="AUDIENCE" content="NBUSER"/> |
| <meta name="TYPE" content="ARTICLE"/> |
| <meta name="EXPIRES" content="N"/> |
| <meta name="indexed" content="y"/> |
| <meta name="description" content="A short demonstration of how to use Maven to create and run a NetBeans Platform Module Suite."/> |
| <!-- Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. --> |
| <!-- Use is subject to license terms.--> |
| </head> |
| <body> |
| |
| <h1>Creating a NetBeans Module Using Maven</h1> |
| |
| <p>This document demonstrates how to create a NetBeans Module project from a Maven archetype |
| and build and install the module in your installation of the IDE. |
| In this tutorial you will create a simple module project that when installed enables you to create a new file type |
| in your projects. The module also creates a menu action that is available when you the new file type is selected. |
| </p> |
| |
| <p>This document is based on the Ant-based <a href="https://platform.netbeans.org/tutorials/nbm-filetype.html">NetBeans File Type Tutorial</a> |
| and illustrates some of the differences between using Ant and Maven to develop NetBeans modules. |
| After you understand some of the differences, you can easily proceed through other |
| tutorials on the <a href="https://netbeans.org/kb/trails/platform.html">NetBeans Platform Learning Trail</a>.</p> |
| |
| <p class="tips">If you are new to the NetBeans Platform, you might want to watch the |
| the screencast series <a href="https://platform.netbeans.org/tutorials/nbm-10-top-apis.html">Top 10 NetBeans APIs</a>.</p> |
| |
| <p><b>Contents</b></p> |
| <p><img src="../../images/articles/69/netbeans-stamp69.png" class="stamp" width="114" height="114" alt="Content on this page applies to NetBeans IDE 6.5, 6.7, 6.8" title="Content on this page applies to NetBeans IDE 6.5, 6.7, 6.8"/></p> |
| |
| <ul class="toc"> |
| <li><a href="#config">Using Maven with the IDE</a> |
| <ul> |
| <li><a href="#config1">Configuring Maven Options</a></li> |
| <li><a href="#config2">Viewing the Maven Repositories</a></li> |
| </ul></li> |
| <li><a href="#01">Creating the NetBeans Platform Module Project</a> |
| <ul> |
| <li><a href="#01a">Creating the Module</a></li> |
| <li><a href="#01b">Creating the DataObject Class</a></li> |
| </ul> |
| </li> |
| <li><a href="#02">Building and Running the Module Project</a> |
| <ul> |
| <li><a href="#02a">Specifying the Location of the NetBeans Installation</a></li> |
| <li><a href="#02b">Running the Module</a></li> |
| </ul> |
| </li> |
| <li><a href="#03">Adding an Action for the File Type</a> |
| <ul> |
| <li><a href="#03a">Creating the Action Class</a></li> |
| <li><a href="#03b">Assigning a Behavior to the Action</a></li> |
| </ul> |
| </li> |
| <li><a href="#04">Creating a Window for the File Type</a></li> |
| <li><a href="#05">Creating a Multiview Window</a></li> |
| </ul> |
| |
| <p><b>To follow this tutorial, you need the software and resources listed in the following table.</b></p> |
| |
| <table> |
| <tbody> |
| <tr> |
| <th class="tblheader" scope="col">Software or Resource</th> |
| <th class="tblheader" scope="col">Version Required</th> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="http://download.netbeans.org/">NetBeans IDE</a></td> |
| <td class="tbltd1">version 6.9</td> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="http://java.sun.com/javase/downloads/index.jsp">Java Developer Kit (JDK)</a></td> |
| <td class="tbltd1">Version 6</td> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="http://maven.apache.org/">Maven</a></td> |
| <td class="tbltd1">Version 2.0.9 or higher</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p><strong class="notes">Note:</strong> You do not need to download a separate version |
| of the NetBeans Platform to develop applications for the NetBeans Platform. |
| Typically, you develop the applications and modules in the NetBeans IDE and |
| then only include the modules that are necessary to run the NetBeans Platform and your application.</p> |
| |
| <p>Before starting this tutorial you may want to familiarize yourself with |
| the following documentation.</p> |
| <ul> |
| <li><a href="http://wiki.netbeans.org/MavenBestPractices">Best Practices for Apache Maven in NetBeans 6.x</a></li> |
| <li><a href="http://www.sonatype.com/books/maven-book/reference/introduction.html">Chapter 1. Introducing Apache Maven</a> |
| (from <a href="http://www.sonatype.com/books/maven-book/reference/public-book.html">Maven: The Definitive Guide</a>)</li> |
| <li><a href="https://netbeans.org/kb/docs/java/gui-functionality.html">Introduction to GUI Building</a></li> |
| </ul> |
| |
| |
| |
| |
| |
| |
| |
| <!-- =================================================================== --> |
| <!-- +++++++++++++++ Configuring Maven +++++++++++++++++++++++++++++++++ --> |
| |
| <h2><a name="config"></a>Using Maven with the IDE</h2> |
| <p>If this is your first Maven project you will want to familiarize yourself with the Maven configuration settings |
| and the Maven Repository Browser.</p> |
| |
| <div class="indent"> |
| <a name="config1"></a> |
| <h3>Configuring Maven Options</h3> |
| <p>You can use the Maven tab in the Options window to configure the behavior of Maven in the IDE and to check |
| that your configuration is correct.</p> |
| |
| <ol> |
| <li>Select the Miscellaneous category in the Options window and click the Maven tab.</li> |
| <li>Specify the location of your local Maven installation (requires 2.0.9 or newer).</li> |
| <li>Check that the location of the local Maven repository is correct.</li> |
| <li>Click OK.</li> |
| </ol> |
| <p>In most cases, if your Maven configuration is typical the information in the Options window should already be correct.</p> |
| |
| <p class="notes"><strong>Note.</strong> Maven support is activated as part of the Java SE feature set. |
| If the Maven tab is not available in the Options window, confirm that Java SE is activated by creating a Java application.</p> |
| |
| <h3><a name="config2"></a>Viewing the Maven Repositories</h3> |
| <p>The artifacts that are used by Maven to build all your projects are stored in your local Maven repository. |
| When an artifact is declared as a project dependency, the artifact is downloaded to your local repository |
| from one of the registered remote repositories.</p> |
| |
| <p>The NetBeans repository and several well-known indexed Maven repositories are registered and listed in the Repository Browser window by default. |
| The NetBeans repository contains most of the public artifacts necessary for you to build your project. |
| You can use the Maven Repository Browser to view the contents of your local and remote repositories. |
| You can expand the Local Repository node to see the artifacts that are present locally. |
| The artifacts listed under the NetBeans repository nodes can be added as project dependencies, but not all of |
| them are present locally. They are only added to the Local Repository when they are declared as project |
| dependencies.</p> |
| |
| <p>To open the Maven Repository Browser:</p> |
| <ul> |
| <li>Choose Window > Other > Maven Repository Browser from the main menu.<br/> |
| <img src="../../images/tutorials/maven-quickstart68/maven-nbm-netbeans-repo.png" alt="Screenshot of Maven Repository Browser" title="Screenshot of Maven Repository Browser" class="margin-around b-all" /> |
| |
| </li> |
| </ul> |
| </div> |
| |
| |
| <!-- =================================================================== --> |
| <!-- ++++++++++++++++++++++ Creating the Module ++++++++++++++++++++++++ --> |
| |
| <h2><a name="01"></a>Creating the NetBeans Platform Module Project</h2> |
| <p>In this section you create a NetBeans Module project and then create a DataObject for the new file type.</p> |
| <div class="indent"> |
| <h3><a name="01a"></a>Creating the Module</h3> |
| <p>In this exercise you use the New Project wizard to create the NetBeans Module project from a Maven archetype.</p> |
| <ol> |
| <li>Open the New Project wizard and choose Maven NetBeans Module in the Maven category. Click Next.</li> |
| <li>Type <strong>AbcFileType</strong> in Project Name. Click Finish.</li> |
| </ol> |
| <p>When you click Finish, the IDE creates the AbcFileType project. |
| If you look at the POM you can see that Maven will use the |
| <tt><a href="http://maven.apache.org/plugins/maven-jar-plugin/">maven-jar-plugin</a></tt> to build the JAR and the |
| <tt><a href="http://mojo.codehaus.org/nbm-maven-plugin/">nbm-maven-plugin</a></tt> will package the JAR as a |
| NetBeans Module (<tt>nbm</tt>).</p> |
| |
| <pre class="examplecode"> <modelVersion>4.0.0</modelVersion> |
| <groupId>com.mycompany</groupId> |
| <artifactId>AbcFileType</artifactId> |
| <strong><packaging>nbm</packaging></strong> |
| <version>1.0-SNAPSHOT</version> |
| <name>AbcFileType NetBeans Module</name> |
| ... |
| <build> |
| <plugins> |
| <plugin> |
| <groupId>org.codehaus.mojo</groupId> |
| <strong><artifactId>nbm-maven-plugin</artifactId></strong> |
| <extensions>true</extensions> |
| </plugin> |
| ... |
| <plugin> |
| <groupId>org.apache.maven.plugins</groupId> |
| <strong><artifactId>maven-jar-plugin</artifactId></strong> |
| <version>2.2</version> |
| <configuration> |
| <!-- to have the jar plugin pickup the nbm generated manifest --> |
| <useDefaultManifestFile>true</useDefaultManifestFile> |
| </configuration> |
| </plugin> |
| </plugins> |
| </build></pre> |
| |
| |
| |
| |
| <h3><a name="01b"></a>Creating the DataObject Class</h3> |
| |
| <p>In this section you will use the New File Type wizard to create the files for |
| creating and recognizing a new file type named <tt>.abc</tt>. |
| The wizard will create a |
| <tt><a href="http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/DataObject.html">DataObject</a></tt>, |
| a MIME type resolver and a file template for <tt>abc</tt> files |
| and modify <tt>layer.xml</tt> to add registration entries for the new file type.</p> |
| |
| <ol> |
| <li>Right-click the project node in the Projects window and choose New > File Type.</li> |
| <li>In the File Recognition panel, type <strong>text/x-abc</strong> for the MIME Type and <strong>.abc .ABC</strong> for the Filename Extension. Click Next.<br/> |
| <img src="../../images/tutorials/maven-single/maven-single-new-filetype-wizard.png" alt="Screenshot of New File Type wizard" title="New File Type wizard" class="margin-around b-all" /> |
| </li> |
| <li>Type <strong>Abc</strong> as the Class Name Prefix.</li> |
| <li>Click Browse and select a 16x16 pixel image file as the new file type's icon. Click Finish. |
| <p class="tips">You can save this image <tt><a href="../images/tutorials/maven-crud/abc16.png">abc16.png</a></tt> ( <img src="../../images/tutorials/maven-crud/abc16.png" alt="16x16 icon image" title="16x16" /> ) |
| to you system and specify the image in the wizard.</p> |
| </li> |
| </ol> |
| |
| |
| <p>When you click Finish, the IDE creates the <tt>AbcDataObject</tt> class and |
| copies your file type icon into the package in the <tt>src/main/resources</tt> under Other Sources.<br/> |
| <img src="../../images/tutorials/maven-single/maven-single-projects1.png" alt="Screenshot of Projects window" title="Screenshot of Projects window" class="margin-around b-all" /> |
| |
| </p> |
| <p>In the Projects window you can see that the wizard created the MIME type resolver (<tt>AbcResolver.xml</tt>) |
| and template (<tt>AbcTemplate.abc</tt>) files in the <tt>src/main/resources</tt> directory.</p> |
| |
| <p class="tips">For more details on the files that the IDE created, see |
| <a href="http://wiki.netbeans.org/DevFaqDataObject">What is a DataObject</a> and the section on |
| <a href="nbm-filetype.html#recognizing">Recognizing Abc Files</a> in the <a href="nbm-filetype.html">NBM Filetype tutorial</a>.</p> |
| |
| |
| </div> |
| |
| |
| |
| <!-- =================================================================== --> |
| <!-- ++++++++++++++++++++++ Running the Module ++++++++++++++++++++++++ --> |
| <h2><a name="02"></a>Building and Running the Project</h2> |
| |
| <p>In this section you will configure the module so that the module will be installed into the |
| current version of the IDE. A new instance of the IDE will launch when you run the module. </p> |
| |
| <div class="indent"> |
| <h3><a name="02a"></a>Specifying the Location of the NetBeans Installation</h3> |
| <p>By default, no target NetBeans installation is specified when you use the Maven archetype to create a NetBeans Platform module. |
| You can build the project, but when you try to run the project before you set the installation directory |
| you will see a build error similar to the following in the Output window.<br/> |
| <img src="../../images/tutorials/maven-single/output-build-error.png" alt="Screenshot of Output window showing build error" title="Output window showing build error" class="margin-around b-all" /> |
| |
| </p> |
| <p>To install and run the module in an installation of the IDE you need to edit the <tt>nbm-maven-plugin</tt> |
| element in the POM to specify the path to the installation directory.</p> |
| <ol> |
| <li>Expand the Project Files node and open <tt>pom.xml</tt> in the editor.</li> |
| <li>Specify the path to the NetBeans installation by modifying the <tt>nbm-maven-plugin</tt> |
| element to add the <tt><netbeansInstallation></tt> element. |
| <pre class="examplecode"><plugin> |
| <groupId>org.codehaus.mojo</groupId> |
| <artifactId>nbm-maven-plugin</artifactId> |
| <version>3.2</version> |
| <extensions>true</extensions> |
| <strong><configuration> |
| <netbeansInstallation>/home/me/netbeans-6.9</netbeansInstallation> |
| </configuration></strong> |
| </plugin></pre> |
| <!-- <descriptor>src/main/nbm/module.xml</descriptor> --> |
| <p class="notes"><strong>Note.</strong> The path needs to specify the directory that contains the <tt>bin</tt> directory containing the runnable file.</p> |
| <p>For example, on OS X the path might resemble the following.</p> |
| <pre class="examplecode"><netbeansInstallation>/Applications/NetBeans/NetBeans 6.9.app/Contents/Resources/NetBeans</netbeansInstallation></pre> |
| </li> |
| </ol> |
| |
| <h3><a name="02b"></a>Running the Module</h3> |
| <p>After you specify the NetBeans IDE installation directory you can build and run the module.</p> |
| <ol> |
| <li>Right-click the project node and choose Build.</li> |
| <li>Right-click the project node and choose Run.</li> |
| </ol> |
| <p>When you choose Run, the IDE launches with the new module installed. |
| To confirm that the new module is working correctly, create a new project and then use the New File wizard |
| to create an <tt>abc</tt> file. |
| For example, you can create a simple Java application and then open the New File wizard and |
| choose the Empty Abc file type in the Other category.</p> |
| <p class="tips">When you create the new file, specify a source package if you want to see the file in the Projects window. |
| By default the wizard for the new file type will create the file at the root level of the project.</p> |
| <p><img src="../../images/tutorials/maven-single/wizard-new-abc-file.png" alt="Screenshot of New File wizard with Abc file type" title="New File wizard with Abc file type" class="margin-around b-all" /> |
| <br/> |
| After you create the new abc file you can see that the file is displayed in the Projects window with the icon for the file type. |
| If you open the file in the editor you can see that the contents of the new file were generated from the file template.<br/> |
| <img src="../../images/tutorials/maven-single/maven-single-projects-abcfile.png" alt="Screenshot of Abc file in Projects window and open in editor" title="Abc file in Projects window and open in editor" class="margin-around b-all" /> |
| </p> |
| </div> |
| |
| |
| |
| <!-- =================================================================== --> |
| <!-- +++++++++++++++++++++++ Adding an Action ++++++++++++++++++++++++++ --> |
| <h2><a name="03"></a>Adding an Action for the File Type</h2> |
| <p>In this section you will add an action that can be invoked from |
| the popup menu when the user right-clicks the node of the new file type.</p> |
| |
| <div class="indent"> |
| <h3><a name="03a"></a>Creating the Action Class</h3> |
| <p>In this exercise you will use the New Action wizard to create a Java class that will perform an action for the new file type. |
| The wizard will also register the class in the <tt>layer.xml</tt>.</p> |
| <ol> |
| <li>Right-click the project node and choose New > Action.</li> |
| <li>In the Action Type panel, select Conditionally Enabled and type <strong>com.mycompany.abcfiletype.AbcDataObject</strong> for the Cookie Class. Click Next.<br/> |
| <img src="../../images/tutorials/maven-single/maven-single-newactionwizard.png" alt="Screenshot of New Action wizard" title="New Action wizard" class="margin-around b-all" /> |
| </li> |
| <li>Select Edit in the Category drop-down list and deselect Global Menu Item.</li> |
| <li>Select File Type Context Menu Item and select <strong>text/x-abc</strong> in the Content Type drop-down list. Click Next.</li> |
| <li>Type <strong>MyAction</strong> as the Class Name and <strong>My Action</strong> as the Display Name. Click Finish.</li> |
| </ol> |
| <p>When you click Finish, <tt>MyAction.java</tt> is created in the <tt>com.mycompany.abcfiletype</tt> source package. |
| If you open <tt>layer.xml</tt> in the editor you can see that the wizard added details about the new action |
| for the file type inside the <tt>Edit</tt> folder element inside the <tt>Actions</tt> folder.</p> |
| <pre class="examplecode"> |
| <folder name="Actions"> |
| <folder name="Edit"> |
| <strong><file name="com-mycompany-abcfiletype-MyAction.instance"></strong> |
| <attr name="delegate" methodvalue="org.openide.awt.Actions.inject"/> |
| <attr name="displayName" bundlevalue="com.mycompany.abcfiletype.Bundle#CTL_MyAction"/> |
| <attr name="injectable" stringvalue="com.mycompany.abcfiletype.MyAction"/> |
| <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.context"/> |
| <attr name="noIconInMenu" boolvalue="false"/> |
| <attr name="selectionType" stringvalue="EXACTLY_ONE"/> |
| <attr name="type" stringvalue="com.mycompany.abcfiletype.AbcDataObject"/> |
| </file> |
| </folder> |
| </folder></pre> |
| <p>The wizard also generated elements inside the <tt>Loaders</tt> and <tt>Factories</tt> folder elements |
| that apply to the new file type. The menu actions for the <tt>abc</tt> file type are |
| specified under <tt>Actions</tt> and the <tt>DataLoader</tt> is specified under <tt>Factories</tt>.</p> |
| |
| <pre class="examplecode"> |
| <folder name="Loaders"> |
| <folder name="text"> |
| <strong><folder name="x-abc"> |
| <folder name="Actions"> |
| <file name="com-mycompany-abcfiletype-MyAction.shadow"></strong> |
| <attr name="originalFile" stringvalue="Actions/Edit/com-mycompany-abcfiletype-MyAction.instance"/> |
| <strong><attr name="position" intvalue="0"/></strong> |
| </file> |
| <file name="org-openide-actions-CopyAction.shadow"> |
| <attr name="originalFile" stringvalue="Actions/Edit/org-openide-actions-CopyAction.instance"/> |
| <attr name="position" intvalue="400"/> |
| </file> |
| ... |
| </folder> |
| <strong><folder name="Factories"> |
| <file name="AbcDataLoader.instance"></strong> |
| <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/com/mycompany/abcfiletype/abc16.png"/> |
| <attr name="dataObjectClass" stringvalue="com.mycompany.abcfiletype.AbcDataObject"/> |
| <attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/> |
| <attr name="mimeType" stringvalue="text/x-abc"/> |
| </file> |
| </folder> |
| </folder> |
| </folder> |
| </folder></pre> |
| |
| <p class="tips">The position of My Action in the popup menu is specified by the <tt>position</tt> attribute (<tt><attr name="position" intvalue="0"/></tt>). |
| The default is to assign the <tt>intvalue</tt> of the attribute of a new action to <tt>0</tt> which will make the |
| action the topmost in the list. |
| You can change the order by changing the <tt>intvalue</tt>. |
| For example, if you change the <tt>intvalue</tt> to <tt>200</tt>, the My Action menu item will appear below |
| the Open menu item (the Open action has an <tt>intvalue</tt> of <tt>100</tt>).</p> |
| |
| |
| <h3><a name="03b"></a>Assigning a Behavior to the Action</h3> |
| <p>You now need to add the code for the action. |
| In this example you will add some code that uses <tt>DialogDisplayer</tt> to open a dialog box |
| when the action is invoked from the popup menu. |
| To use <tt>DialogDisplayer</tt> you will also need to declare a direct dependency on <tt>org.openide.dialogs</tt>.</p> |
| <ol> |
| <li>Modify the <tt>actionPerformed(ActionEvent ev)</tt> method in <tt>MyAction.java</tt> to open a dialog when My Action is invoked. |
| <pre class="examplecode">@Override |
| public void actionPerformed(ActionEvent ev) { |
| <strong>FileObject f = context.getPrimaryFile(); |
| String displayName = FileUtil.getFileDisplayName(f); |
| String msg = "This file is " + displayName + "."; |
| NotifyDescriptor nd = new NotifyDescriptor.Message(msg); |
| DialogDisplayer.getDefault().notify(nd);</strong> |
| }</pre> |
| </li> |
| <li>Fix your imports and confirm that you import <tt><strong>org.openide.filesystems.FileObject</strong></tt>. Save your changes. |
| <p>When you fixed the imports you added an import statement for <tt>org.openide.DialogDisplayer</tt>. |
| You now need to declare the dependency on the <tt>org.openide.dialogs</tt> artifact a direct dependency instead of a transitive dependency.</p></li> |
| <li>Right-click the <tt>org.openide.dialogs</tt> JAR under the project's Libraries node and choose Declare as Direct Dependency.</li> |
| </ol> |
| <p>You can now test the module to confirm that the new action works correctly.</p> |
| <p class="notes"><strong>Note.</strong> To run the module you will first need to clean and build the module.</p> |
| <p><img src="../../images/tutorials/maven-single/maven-single-action-popup.png" alt="Screenshot of Abc file in Projects window and open in editor" title="Abc file in Projects window and open in editor" class="margin-around b-all" /> |
| </p> |
| <p>When you right-click on a node of the <tt>abc</tt> file type you will see that My Action is one of the items in the popup menu.</p> |
| |
| </div> |
| |
| |
| <!-- =================================================================== --> |
| <!-- +++++++++++++++++++++++ Creating a Window +++++++++++++++++++++++++ --> |
| |
| <h2><a name="04"></a>Creating a Window for the File Type</h2> |
| <p>By default, the new file type will open into a basic text editor. |
| If you do not want to use an editor for the new file type, you can create a new window |
| specifically for editing the new file type. |
| You can then modify the window component to support other ways of editing the file, for example by making the window a visual editor. |
| In this section you will create the new window component specifically for files of your new file type.</p> |
| |
| <ol> |
| <li>Right-click the project node and choose New > Window.</li> |
| <li>Select <strong>editor</strong> from the dropdown list and select Open on Application Start. Click Next.</li> |
| <li>Type <strong>Abc</strong> as the Class Name Prefix. Click Finish.</li> |
| <li>Open <tt>AbcDataObject.java</tt> in the editor and modify the class constructor to use |
| <tt><a href="http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/OpenSupport.html">OpenSupport</a></tt> |
| instead of <tt>DataEditorSupport</tt>. |
| <pre class="examplecode"> |
| public AbcDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { |
| super(pf, loader); |
| CookieSet cookies = getCookieSet(); |
| <strong>cookies.add((Node.Cookie) new AbcOpenSupport(getPrimaryEntry()));</strong> |
| }</pre> |
| </li> |
| <li>Create the <tt>AbcOpenSupport</tt> class that is called by the constructor. |
| <p class="tips">Type Alt-Enter in the line containing the call to <tt>AbcOpenSupport</tt> to |
| create <tt>AbcOpenSupport</tt> in the package <tt>com.mycompany.abcfiletype</tt>.</p></li> |
| <li>Modify <tt>AbcOpenSupport</tt> to extend <tt>OpenSupport</tt> and implement <tt>OpenCookie</tt> and <tt>CloseCookie</tt>. |
| <pre class="examplecode"> |
| class AbcOpenSupport <strong>extends OpenSupport implements OpenCookie, CloseCookie</strong> {</pre> |
| </li> |
| <li>Implement the abstract methods (Alt-Enter) and make the following changes to the class. |
| <pre class="examplecode"> |
| public AbcOpenSupport(<strong>AbcDataObject.Entry entry</strong>) { |
| <strong>super(entry);</strong> |
| } |
| |
| @Override |
| protected CloneableTopComponent createCloneableTopComponent() { |
| <strong>AbcDataObject dobj = (AbcDataObject) entry.getDataObject(); |
| AbcTopComponent tc = new AbcTopComponent(); |
| tc.setDisplayName(dobj.getName()); |
| return tc;</strong> |
| }</pre> |
| </li> |
| <li>Open <tt>AbcTopComponent</tt> in the editor and modify the class to extend <tt>CloneableTopComponent</tt> |
| instead of <tt>TopComponent</tt>. |
| <pre class="examplecode">public final class AbcTopComponent extends <strong>CloneableTopComponent</strong> {</pre> |
| </li> |
| <li>Change the class modifier from <tt>private</tt> to <tt>public</tt>. |
| <pre class="examplecode"><strong>public</strong> static AbcTopComponent instance;</pre> |
| </li> |
| <li>Fix your imports and save your changes.</li> |
| </ol> |
| <p>You can now try running the module again after cleaning and building the project.<br/> |
| <img src="../../images/tutorials/maven-single/maven-single-newfile-window.png" alt="Screenshot of Abc file in Projects window and open in editor" title="Abc file in Projects window and open in editor" class="margin-around b-all" /></p> |
| <p>When you open an abc file the file will now open in the new window instead of the basic editor.</p> |
| |
| |
| |
| |
| |
| |
| |
| |
| <!--<p>The project also contains other XML files containing metadata about the project such as <tt>profiles.xml</tt>. |
| The <tt>profiles.xml</tt> file specifies the path to the NetBeans installation and is used by the IDE when running the project. |
| --> |
| |
| <!--<p>Unlike the original Ant-based tutorial, you do not specify the platform installation in the wizard. |
| For Maven module suites you need to modify the <tt><netbeans.installation></tt> element in the profiles.xml file |
| and explicitly specify the path to the NetBeans platform installation. </p> |
| see https://netbeans.org/bugzilla/show_bug.cgi?id=185941. |
| --> |
| |
| |
| |
| <p>This tutorial demonstrated how to create and run a NetBeans Module that you create from a Maven Archetype. |
| You learned how to modify the project POM to specify the target NetBeans installation so that |
| the Run command in the IDE will install the module and launch a new instance of the IDE. |
| You also learned a little about how to work with file types and <tt>DataObjects</tt>, but for more details you should look at |
| the <a href="https://platform.netbeans.org/tutorials/nbm-filetype.html">NetBeans File Type Tutorial</a>. |
| For more examples on how to build NetBeans Platform applications and modules, |
| see the tutorials listed in the <a href="https://netbeans.org/kb/trails/platform.html">NetBeans Platform Learning Trail</a>.</p> |
| |
| |
| <!-- ======================================================================================== --> |
| <div class="feedback-box"><a name="feedback"></a> |
| <a href="https://netbeans.org/about/contact_form.html?to=3&subject=Feedback:%20Creating%20a%20NetBeans%20Module%20Using%20Maven"> |
| Send Us Your Feedback</a></div> |
| |
| <p> </p> |
| <!-- ======================================================================================== --> |
| |
| |
| <h2><a name="nextsteps"></a>See Also</h2> |
| |
| <p>For more information about creating and developing applications, see the following resources.</p> |
| <ul> |
| <li><a href="https://netbeans.org/kb/trails/platform.html">NetBeans Platform Learning Trail</a></li> |
| <li><a href="http://bits.netbeans.org/dev/javadoc/">NetBeans API Javadoc</a></li> |
| </ul> |
| <p>If you have any questions about the NetBeans Platform, feel free |
| to write to the mailing list, dev@platform.netbeans.org, or view the |
| <a href="https://netbeans.org/projects/platform/lists/dev/archive">NetBeans Platform mailing list archive</a>.</p> |
| |
| |
| <!-- ======================================================================================== --> |
| |
| |
| |
| </body> |
| |
| </html> |