| <!doctype html> |
| <html class="no-js" lang="en" dir="ltr"> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="x-ua-compatible" content="ie=edge"> |
| <title>NetBeans Platform Ant Command Line Tutorial</title> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <meta name="description" content="NetBeans Platform Ant Command Line Tutorial - Apache NetBeans"> |
| <meta name="author" content="Apache NetBeans"> |
| <meta name="description" content="NetBeans Platform Ant Command Line Tutorial - Apache NetBeans"> |
| <meta name="keywords" content="Apache NetBeans Platform, Platform Tutorials, NetBeans Platform Ant Command Line Tutorial"> |
| <meta name="generator" content="Apache NetBeans"> |
| <link rel="stylesheet" href="../../../../_/css/font-awesome.min.css"> |
| <link rel="alternate" type="application/atom+xml" title="Apache NetBeans Blog" href="https://netbeans.apache.org/blogs/atom" /> |
| <link rel="stylesheet" href="../../../../_/css/highlightjs/default.min.css"> |
| <link rel="stylesheet" href="../../../../_/css/netbeans.css"> |
| <link rel="apple-touch-icon" sizes="180x180" href="../../../../_/images/fav/apple-touch-icon.png"> |
| <link rel="icon" type="image/png" sizes="32x32" href="../../../../_/images/fav/favicon-32x32.png"> |
| <link rel="icon" type="image/png" sizes="16x16" href="../../../../_/images/fav/favicon-16x16.png"> |
| <link rel="manifest" href="../../../../_/images/fav/site.webmanifest"> |
| <link rel="mask-icon" href="../../../../_/images/fav/safari-pinned-tab.svg" color="#5bbad5"> |
| <meta name="msapplication-TileColor" content="#ffc40d"> |
| <meta name="theme-color" content="#ffffff"> |
| <link href="../../../../_/css/font-open-sans.css" rel="stylesheet"> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| http://www.apache.org/licenses/LICENSE-2.0 |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| </head> |
| <body> |
| <div class="title-bar" data-responsive-toggle="responsive-menu" data-hide-for="medium"> |
| <button type="button" data-toggle="responsive-menu"><i style='font-size: 32px; color: #fff; padding: 8px' class='fa fa-bars'></i></button> |
| <div class="title-bar-title">Apache NetBeans</div> |
| </div> |
| <div class="top-bar" id="responsive-menu"> |
| <div class='top-bar-left'> |
| <a class='title' href="../../../../index.html"><img src='../../../../_/images/apache-netbeans.svg' style='padding: 8px; height: 48px;'> Apache NetBeans</a> |
| </div> |
| <div class="top-bar-right"> |
| <ul class="vertical medium-horizontal menu" data-responsive-menu="drilldown medium-dropdown"> |
| <li> <input id="search-input" type="text" placeholder="Search the docs"> </li> |
| <li> <a href="../../../../front/main/community">Community</a> </li> |
| <li> <a href="../../../../front/main/participate">Participate</a> </li> |
| <li> <a href="../../../../front/main/blogs">Blog</a></li> |
| <li> <a href="../../../../front/main/help">Get Help</a> </li> |
| <li> <a href="https://plugins.netbeans.apache.org/">Plugins</a> </li> |
| <li> <a href="../../../../front/main/download">Download</a> </li> |
| </ul> |
| </div> |
| </div> |
| |
| <!-- src/templates/news --> |
| <section class="hero news alternate"> |
| <div class='grid-container'> |
| <div class='cell'> |
| <div class="annotation">Latest release</div> |
| <h1>Apache NetBeans 27</h1> |
| <p><a class="button success" href="../../../../front/main/download/nb27">Download</a></p> |
| </div> |
| </div> |
| </section> |
| <div class='grid-container main-content tutorial'> |
| <h1 class="sect0">NetBeans Platform Ant Command Line Tutorial</h1> |
| <div class="sectionbody"> |
| <div class="admonitionblock note"> |
| <table> |
| <tbody><tr> |
| <td class="icon"><i class="fa icon-note" title="Note"></i></td> |
| <td class="content">This tutorial needs a review. |
| You can <a href="https://github.com/apache/netbeans-antora-tutorials/edit/main/modules/ROOT/pages/tutorials/nbm-ant.adoc" title="Edit this tutorial in github">edit it in GitHub </a> |
| following these <a href="../../../../tutorial/main/kb/docs/contributing">contribution guidelines.</a></td> |
| </tr></tbody> |
| </table> |
| </div> |
| </div> |
| <div id="toc" class="toc"> |
| <div id="toctitle"></div> |
| <ul class="sectlevel1"> |
| <li><a href="#_downloading_the_netbeans_platform">Downloading the NetBeans Platform</a></li> |
| <li><a href="#_setting_up_a_netbeans_platform_application">Setting Up a NetBeans Platform Application</a></li> |
| <li><a href="#_setting_up_a_netbeans_module">Setting Up a NetBeans Module</a></li> |
| <li><a href="#_adding_a_menu_item">Adding a Menu Item</a></li> |
| <li><a href="#_adding_a_window">Adding a Window</a></li> |
| </ul> |
| </div> |
| <div id="preamble"> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>This document shows you how to use Ant and the command line to set up and deploy NetBeans Platform applications.</p> |
| </div> |
| <div class="paragraph"> |
| <p>You will start by setting up a folder and file structure for deploying a NetBeans Platform application. The structure will consist of folders, together with Ant scripts and property files. For example, one of the Ant targets will download the NetBeans Platform, while another will run it. Next, you will create a new folder and file structure for adding a new module to the application. Finally, you will add code that will enable your module to provide new components, such as a new menu item, to the application.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Once you have gone through this simple scenario, you should not <em>need</em> to use NetBeans IDE at all when creating NetBeans Platform applications. On the other hand, you might still <em>want</em> to use NetBeans IDE, since it provides many wizards, templates, and other tools for generating code and visualizing module structures, which are features that no other IDE currently provides. Simultaneously, the instructions below provide all the NetBeans-specific information needed for someone to create a plugin for a different IDE enabling developers to use other IDEs to provide the folder structures and file contents outlined below.</p> |
| </div> |
| <div class="paragraph"> |
| <p>For troubleshooting purposes, you are welcome to download the <a href="http://web.archive.org/web/20170409072842/http://java.net/projects/nb-api-samples/show/versions/8.0/tutorials/ABC">completed tutorial source code</a>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The tutorial assumes you have set up Ant and that you know how to use it.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_downloading_the_netbeans_platform"><a class="anchor" href="#_downloading_the_netbeans_platform"></a>Downloading the NetBeans Platform</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>In this section, you begin to set up a folder structure for your NetBeans Platform work, focusing on an Ant script to download the NetBeans Platform.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="1"> |
| <li> |
| <p>Create a new folder with a name of your choosing (here referred to as <code>ABC</code>) and, within it, create a folder named <code>myapp</code> (or any other name), containing a file named <code>build.xml</code>. At this point the structure of your application should be as follows:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_ant-structure-0.png" alt="ant ant structure 0"> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="2"> |
| <li> |
| <p>Read <a href="#wiki::wiki/AutoUpdateTask">[wiki::wiki/AutoUpdateTask]</a>.</p> |
| </li> |
| </ol> |
| </div> |
| <div class="paragraph"> |
| <p>1. |
| Define the content of the <code>build.xml</code> file as follows:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><?xml version="1.0" encoding="UTF-8"?> |
| |
| <project name="myapp" basedir="."> |
| |
| <description>Builds, tests, and runs the project "myapp".</description> |
| |
| <!-- change this: --> |
| <property name="netbeans" |
| value="/home/geertjan/NetBeansProjects/ABC/nbrcp"/> |
| |
| <property name="bootstrap.url" |
| value="http://deadlock.netbeans.org/hudson/job/nbms-and-javadoc/lastStableBuild/artifact/nbbuild/netbeans/harness/tasks.jar"/> |
| |
| <property name="netbeans.updatecenter.url" |
| value="http://updates.netbeans.org/netbeans/updates/8.0/uc/final/distribution/catalog.xml.gz"/> |
| |
| <target name="download-netbeans-rcp"> |
| <mkdir dir="${netbeans}/harness"/> |
| <get src="${bootstrap.url}" dest="${netbeans}/harness/tasks.jar" usetimestamp="true" verbose="true"/> |
| <taskdef name="autoupdate" classname="org.netbeans.nbbuild.AutoUpdate" classpath="${netbeans}/harness/tasks.jar"/> |
| <autoupdate installdir="${netbeans}" updatecenter="${netbeans.updatecenter.url}"> |
| <modules includes=".*" clusters="harness[0-9]*"/> |
| <modules includes=".*" clusters="platform[0-9]*"/> |
| </autoupdate> |
| </target> |
| |
| </project></code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="4"> |
| <li> |
| <p>On the command line, go to the "ABC/myapp" folder and run this:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">ant download-netbeans-rcp</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>You now see the NetBeans Platform downloading:</p> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_ant-download.png" alt="ant ant download"> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>In your ABC folder, you now have a folder named "nbrcp", as shown below:</p> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_ant-structure-1.png" alt="ant ant structure 1"> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Read <code>harness/README</code> for a lot of tips, configuration data, and advice.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The folder "myapp" is where you will create your application, on top of the NetBeans Platform, which is in the folder "nbrcp".</p> |
| </div> |
| <div class="paragraph"> |
| <p>Now that you have the NetBeans Platform, you can start creating an application on top of it.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_setting_up_a_netbeans_platform_application"><a class="anchor" href="#_setting_up_a_netbeans_platform_application"></a>Setting Up a NetBeans Platform Application</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>In this section, you set up a minimal folder and file structure for a new NetBeans Platform application.</p> |
| </div> |
| <div class="paragraph"> |
| <p>At the end of this section, you will have a source structure on disk, as follows:</p> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_ant-structure.png" alt="ant ant structure"> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="1"> |
| <li> |
| <p>Within the "myapp" folder, create a folder named "nbproject". This folder will, from now onwards, be referred to as the "application project folder", while "myapp" will be referred to as the "application root folder".</p> |
| </li> |
| </ol> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="2"> |
| <li> |
| <p>Within the application project folder, create a file named <code>build-impl.xml</code>, with the following content.</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><?xml version="1.0" encoding="UTF-8"?> |
| |
| <project name="myapp-impl" basedir=".." xmlns:sproject="https://netbeans.org/ns/nb-module-suite-project/1"> |
| |
| <property file="nbproject/platform.properties"/> |
| |
| <macrodef name="property" uri="https://netbeans.org/ns/nb-module-suite-project/1"> |
| <attribute name="name"/> |
| <attribute name="value"/> |
| <sequential> |
| <property name="@{name}" value="${@{value}}"/> |
| </sequential> |
| </macrodef> |
| |
| <macrodef name="evalprops" uri="https://netbeans.org/ns/nb-module-suite-project/1"> |
| <attribute name="property"/> |
| <attribute name="value"/> |
| <sequential> |
| <property name="@{property}" value="@{value}"/> |
| </sequential> |
| </macrodef> |
| |
| <sproject:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir"/> |
| |
| <sproject:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir"/> |
| |
| <sproject:evalprops property="cluster.path.evaluated" value="${cluster.path}"/> |
| |
| <import file="${harness.dir}/suite.xml"/> |
| |
| </project></code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="3"> |
| <li> |
| <p>Import the <code>build-impl.xml</code> file into the <code>build.xml</code> file, as follows:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"><import file="nbproject/build-impl.xml"/></code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The <code>build-impl.xml</code> file gives you access to the NetBeans Platform infrastructure, such as its "run" target. You will never need to change the <code>build-impl.xml</code> file. On the other hand, the <code>build.xml</code> file is the Ant script where you will customize, where necessary, your application’s build process.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="4"> |
| <li> |
| <p>Within the application project folder, create a file named <code>platform.properties</code>, with the following content.</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">run.args.extra=--laf Nimbus |
| nbplatform.active=default |
| nbplatform.active.dir=/home/geertjan/NetBeansProjects/ABC/nbrcp |
| harness.dir=${nbplatform.active.dir}/harness |
| cluster.path=${nbplatform.active.dir}/platform |
| disabled.modules=</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>As you can see, the <code>platform.properties</code> file configures your NetBeans Platform application, pointing to its <code>harness</code> and the <code>platform</code> folders, as well as a placeholder for the modules you will disable, later in your development work. Make sure to change <code>nbplatform.active.dir</code> above to point to your "nbrcp" folder.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="5"> |
| <li> |
| <p>Within the application project folder, create a file named <code>project.properties</code>, with the following content.</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">app.name=myapp |
| branding.token=${app.name} |
| modules=</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>As you can see, the <code>project.properties</code> file is focused on the application. In this case, you have added keys in the file for the name of the application and the custom modules that the application will provide.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="6"> |
| <li> |
| <p>On the command line, go to the "ABC/myapp" folder and run this:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">ant run</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The NetBeans Platform starts up and you see a main window, with a menu bar and a tool bar, as shown below:</p> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_80_ant-first-run.png" alt="ant 80 ant first run"> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Try out some of the toolbar buttons and menu items, to see what the NetBeans Platform provided by default.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_setting_up_a_netbeans_module"><a class="anchor" href="#_setting_up_a_netbeans_module"></a>Setting Up a NetBeans Module</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>In this section, you set up a minimal folder and file structure for a new NetBeans module in your NetBeans Platform application. In the process, you also register the module with the application so that, when the application starts up, it will load the module together with the default NetBeans Platform modules making up the application.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="1"> |
| <li> |
| <p>Start by creating some folders:</p> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>Within the "myapp" folder, create a folder named "mymodule". This folder will, from now onwards, be referred to as the "module root folder".</p> |
| </li> |
| <li> |
| <p>Within the module root folder, create a new folder named "nbproject", which will, from now onwards, be referred to as the "module project folder".</p> |
| </li> |
| <li> |
| <p>Within the module root folder, create a new folder structure "src/org/demo/mymodule", which will be the main package.</p> |
| </li> |
| </ul> |
| </div> |
| </li> |
| </ol> |
| </div> |
| <div class="paragraph"> |
| <p>Check that the structure you have created is now as follows:</p> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_ant-structure-2.png" alt="ant ant structure 2"> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="2"> |
| <li> |
| <p>In the module project folder, create the following:</p> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>A file named <code>suite.properties</code>, with this content:</p> |
| </li> |
| </ul> |
| </div> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">suite.dir=${basedir}/..</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The above points to the "myapp" folder, specifying that it is the application that owns this module.</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>A file named <code>project.properties</code>, with this content:</p> |
| </li> |
| </ul> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">javac.source=1.6 |
| javac.compilerargs=-Xlint -Xlint:-serial</code></pre> |
| </div> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>A file named <code>project.xml</code>, with this content:</p> |
| </li> |
| </ul> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><?xml version="1.0" encoding="UTF-8"?> |
| <project xmlns="https://netbeans.org/ns/project/1"> |
| <type>org.netbeans.modules.apisupport.project</type> |
| <configuration> |
| <data xmlns="https://netbeans.org/ns/nb-module-project/3"> |
| <code-name-base>org.demo.mymodule</code-name-base> |
| <suite-component/> |
| <module-dependencies> |
| </module-dependencies> |
| <public-packages/> |
| </data> |
| </configuration> |
| </project></code></pre> |
| </div> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>A file named <code>build-impl.xml</code>, with this content:</p> |
| </li> |
| </ul> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><?xml version="1.0" encoding="UTF-8"?> |
| |
| <project name="org.demo.mymodule-impl" basedir=".."> |
| |
| <property file="nbproject/suite.properties"/> |
| |
| <property file="${suite.dir}/nbproject/platform.properties"/> |
| |
| <macrodef name="property" uri="https://netbeans.org/ns/nb-module-project/2"> |
| <attribute name="name"/> |
| <attribute name="value"/> |
| <sequential> |
| <property name="@{name}" value="${@{value}}"/> |
| </sequential> |
| </macrodef> |
| |
| <macrodef name="evalprops" uri="https://netbeans.org/ns/nb-module-project/2"> |
| <attribute name="property"/> |
| <attribute name="value"/> |
| <sequential> |
| <property name="@{property}" value="@{value}"/> |
| </sequential> |
| </macrodef> |
| |
| <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="https://netbeans.org/ns/nb-module-project/2"/> |
| <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="https://netbeans.org/ns/nb-module-project/2"/> |
| <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="https://netbeans.org/ns/nb-module-project/2"/> |
| |
| <import file="${harness.dir}/build.xml"/> |
| |
| </project></code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="3"> |
| <li> |
| <p>In the module root folder, that is, within the "mymodule" folder, create the following:</p> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>A file named <code>build.xml</code>, with the following content:</p> |
| </li> |
| </ul> |
| </div> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><?xml version="1.0" encoding="UTF-8"?> |
| <project name="org.demo.mymodule" default="netbeans" basedir="."> |
| <description>Builds, tests, and runs the project org.demo.mymodule.</description> |
| <import file="nbproject/build-impl.xml"/> |
| </project></code></pre> |
| </div> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>A file named <code>manifest.mf</code>, with the following content:</p> |
| </li> |
| </ul> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">Manifest-Version: 1.0 |
| OpenIDE-Module: org.demo.mymodule |
| OpenIDE-Module-Specification-Version: 1.0</code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="4"> |
| <li> |
| <p>Check that the "mymodule" structure you have created is now as follows:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_ant-structure-3.png" alt="ant ant structure 3"> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="5"> |
| <li> |
| <p>In the application project folder, that is, "myapp/nbproject", change the "modules" key in "project.properties" to the following, to register the module with the application:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">modules=${project.org.demo.mymodule} |
| |
| project.org.demo.mymodule=mymodule</code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="6"> |
| <li> |
| <p>On the command line, go to the "ABC/myapp" folder and run this:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">ant run</code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="7"> |
| <li> |
| <p>The application starts up and, since you didn’t add any code to the module, you see no changes in the application. Nevertheless, looking at the output, you can see that the module loaded successfully:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_ant-result-1.png" alt="ant ant result 1"> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>In the next section, you add a new feature to the application.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_adding_a_menu_item"><a class="anchor" href="#_adding_a_menu_item"></a>Adding a Menu Item</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>In this section, you add a menu item to the module you created in the previous section. All the files described below are assumed to be created in the main package, which is <code>org.demo.mymodule</code>.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="1"> |
| <li> |
| <p>Add a new Action class, in a file named "HelloWorldAction.java", to the module:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">package org.demo.mymodule; |
| |
| import java.awt.event.ActionEvent; |
| import java.awt.event.ActionListener; |
| import javax.swing.JOptionPane; |
| import org.openide.awt.ActionRegistration; |
| import org.openide.awt.ActionReference; |
| import org.openide.awt.ActionReferences; |
| import org.openide.awt.ActionID; |
| import org.openide.util.NbBundle.Messages; |
| |
| @ActionID(category = "Window", |
| id = "org.demo.mymodule.HelloWorldAction") |
| @ActionRegistration(displayName = "#CTL_HelloWorldAction") |
| @ActionReferences({ |
| @ActionReference(path = "Menu/Window", position = -100) |
| }) |
| @Messages("CTL_HelloWorldAction=Hello World") |
| public final class HelloWorldAction implements ActionListener { |
| |
| public void actionPerformed(ActionEvent e) { |
| JOptionPane.showMessageDialog(null, "hello..."); |
| } |
| |
| }</code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="2"> |
| <li> |
| <p>In the module project folder, add the list of module dependencies to the "project.xml" file, as shown below:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><?xml version="1.0" encoding="UTF-8"?> |
| <project xmlns="https://netbeans.org/ns/project/1"> |
| <type>org.netbeans.modules.apisupport.project</type> |
| <configuration> |
| <data xmlns="https://netbeans.org/ns/nb-module-project/3"> |
| <code-name-base>org.demo.mymodule</code-name-base> |
| <suite-component/> |
| *<module-dependencies> |
| <dependency> |
| <code-name-base>org.netbeans.modules.settings</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <release-version>1</release-version> |
| <specification-version>1.29</specification-version> |
| </run-dependency> |
| </dependency> |
| <dependency> |
| <code-name-base>org.openide.awt</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <specification-version>6.7.1</specification-version> |
| </run-dependency> |
| </dependency> |
| <dependency> |
| <code-name-base>org.openide.util</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <specification-version>8.1</specification-version> |
| </run-dependency> |
| </dependency> |
| </module-dependencies>* |
| <public-packages/> |
| </data> |
| </configuration> |
| </project></code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="3"> |
| <li> |
| <p>On the command line, go to the "ABC/myapp" folder and run this:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">ant run</code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="4"> |
| <li> |
| <p>The application starts up and shows a new menu item under the Window menu:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_80_ant-action-run.png" alt="ant 80 ant action run"> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_adding_a_window"><a class="anchor" href="#_adding_a_window"></a>Adding a Window</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>In this section, you use the NetBeans TopComponent class to add a window to the module you created previously. All the files described below are assumed to be created in the main package, which is <code>org.demo.mymodule</code>.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="1"> |
| <li> |
| <p>Add a new TopComponent class to the module, including some code for initializing and persisting the TopComponent:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">package org.demo.mymodule; |
| |
| import org.openide.awt.ActionID; |
| import org.openide.awt.ActionReference; |
| import org.openide.windows.TopComponent; |
| import org.openide.util.NbBundle.Messages; |
| import static org.demo.mymodule.Bundle.*; |
| |
| @TopComponent.Description(preferredID = "HelloTopComponent", |
| persistenceType = TopComponent.PERSISTENCE_ALWAYS) |
| @TopComponent.Registration(mode = "editor", openAtStartup = true) |
| @ActionID(category = "Window", id = "org.demo.mymodule.HelloTopComponent") |
| @ActionReference(path = "Menu/Window" /*, position = 333 */) |
| @TopComponent.OpenActionRegistration(displayName = "#CTL_HelloAction", |
| preferredID = "HelloTopComponent") |
| @Messages( |
| {"CTL_HelloAction=Open Hello Window", |
| "NAME_Hello=Hello Window" |
| }) |
| public class HelloWorldTopComponent extends TopComponent { |
| |
| public HelloWorldTopComponent() { |
| setDisplayName(NAME_Hello()); |
| } |
| |
| @Override |
| public void componentOpened() { |
| } |
| |
| @Override |
| public void componentClosed() { |
| } |
| |
| }</code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="2"> |
| <li> |
| <p>In the module project folder, add the following module dependencies in the <code>project.xml</code> file:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><module-dependencies> |
| <dependency> |
| <code-name-base>org.netbeans.modules.settings</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <release-version>1</release-version> |
| <specification-version>1.29</specification-version> |
| </run-dependency> |
| </dependency> |
| <dependency> |
| <code-name-base>org.openide.awt</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <specification-version>6.7.1</specification-version> |
| </run-dependency> |
| </dependency> |
| <dependency> |
| <code-name-base>org.openide.util</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <specification-version>8.1</specification-version> |
| </run-dependency> |
| </dependency> |
| *<dependency> |
| <code-name-base>org.openide.util.lookup</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <specification-version>8.6.1</specification-version> |
| </run-dependency> |
| </dependency> |
| <dependency> |
| <code-name-base>org.openide.windows</code-name-base> |
| <build-prerequisite/> |
| <compile-dependency/> |
| <run-dependency> |
| <specification-version>6.39.1</specification-version> |
| </run-dependency> |
| </dependency>* |
| </module-dependencies></code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="3"> |
| <li> |
| <p>On the command line, go to the "ABC/myapp" folder and run this:</p> |
| </li> |
| </ol> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">ant run</code></pre> |
| </div> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic" start="4"> |
| <li> |
| <p>The application starts up and shows a new window, which can also be opened from the Window menu.</p> |
| </li> |
| </ol> |
| </div> |
| <div class="imageblock"> |
| <div class="content"> |
| <img src="../../_images/tutorials/ant_80_ant-window-run.png" alt="ant 80 ant window run"> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Congratulations, you’ve successfully set up a pure Ant-based application structure for working with the NetBeans Platform.</p> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../../../front/main/community/mailing-lists/" class="xref page">Send Us Your Feedback</a></p> |
| </div> |
| </div> |
| </div> |
| <section class='tools'> |
| <ul class="menu align-center"> |
| <li><a title="Facebook" href="https://www.facebook.com/NetBeans"><i class="fa fa-md fa-facebook"></i></a></li> |
| <li><a title="Twitter" href="https://twitter.com/netbeans"><i class="fa fa-md fa-twitter"></i></a></li> |
| <li><a title="Github" href="https://github.com/apache/netbeans"><i class="fa fa-md fa-github"></i></a></li> |
| <li><a title="YouTube" href="https://www.youtube.com/user/netbeansvideos"><i class="fa fa-md fa-youtube"></i></a></li> |
| <li><a title="Atom Feed" href="https://netbeans.apache.org/blogs/atom"><i class="fa fa-mf fa-rss"></i></a></li> |
| <li><a title="Slack" href="https://tinyurl.com/netbeans-slack-signup/"><i class="fa fa-md fa-slack"></i></a></li> |
| <li><a title="Issues" href="https://github.com/apache/netbeans/issues"><i class="fa fa-mf fa-bug"></i></a></li> |
| </ul> |
| <ul class="menu align-center"> |
| <li><a href="https://github.com/apache/netbeans-antora-tutorials/edit/main/modules/ROOT/pages/tutorials/nbm-ant.adoc" title="See this page in github"><i class="fa fa-md fa-edit"></i> See this page in GitHub.</a></li> |
| </ul> |
| </section> |
| </div> |
| <div class='grid-container incubator-area' style='margin-top: 64px'> |
| <div class='grid-x grid-padding-x'> |
| <div class='large-auto cell text-center'> |
| <a href="https://www.apache.org/"> |
| <img style="height: 60px" title="Apache Software Foundation" src="../../../../_/images/asf_logo_wide.svg" /> |
| </a> |
| </div> |
| <div class='large-auto cell text-center'> |
| <a href="https://www.apache.org/events/current-event.html"> |
| <img style="width:234px; height: 60px;" title="Apache Software Foundation current event" src="https://www.apache.org/events/current-event-234x60.png"/> |
| </a> |
| </div> |
| </div> |
| </div> |
| <footer> |
| <div class="grid-container"> |
| <div class="grid-x grid-padding-x"> |
| <div class="large-auto cell"> |
| <h1><a href="../../../../front/main/about">About</a></h1> |
| <ul> |
| <li><a href="../../../../front/main/community/who">Who's Who</a></li> |
| <li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li> |
| <li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> |
| <li><a href="https://www.apache.org/security/">Security</a></li> |
| </ul> |
| </div> |
| <div class="large-auto cell"> |
| <h1><a href="../../../../front/main/community">Community</a></h1> |
| <ul> |
| <li><a href="../../../../front/main/community/mailing-lists">Mailing lists</a></li> |
| <li><a href="../../../../front/main/community/committer">Becoming a committer</a></li> |
| <li><a href="../../../../front/main/community/events">NetBeans Events</a></li> |
| <li><a href="https://www.apache.org/events/current-event.html">Apache Events</a></li> |
| </ul> |
| </div> |
| <div class="large-auto cell"> |
| <h1><a href="../../../../front/main/participate">Participate</a></h1> |
| <ul> |
| <li><a href="../../../../front/main/participate/submit-pr">Submitting Pull Requests</a></li> |
| <li><a href="../../../../front/main/participate/report-issue">Reporting Issues</a></li> |
| <li><a href="../../../../front/main/participate/#documentation">Improving the documentation</a></li> |
| </ul> |
| </div> |
| <div class="large-auto cell"> |
| <h1><a href="../../../../front/main/help">Get Help</a></h1> |
| <ul> |
| <li><a href="../../../../front/main/help/#documentation">Documentation</a></li> |
| <li><a href="../../../../wiki/main/wiki">Wiki</a></li> |
| <li><a href="../../../../front/main/help/#support">Community Support</a></li> |
| <li><a href="../../../../front/main/help/commercial-support">Commercial Support</a></li> |
| </ul> |
| </div> |
| <div class="large-auto cell"> |
| <h1><a href="../../../../front/main/download">Download</a></h1> |
| <ul> |
| <li><a href="../../../../front/main/download">Releases</a></li> |
| <li><a href="https://plugins.netbeans.apache.org/">Plugins</a></li> |
| <li><a href="../../../../front/main/download/#_daily_builds_and_building_from_source">Building from source</a></li> |
| <li><a href="../../../../front/main/download/#_older_releases">Previous releases</a></li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </footer> |
| <div class='footer-disclaimer'> |
| <div class="footer-disclaimer-content"> |
| <p>Copyright © 2017-2025 <a href="https://www.apache.org">The Apache Software Foundation</a>.</p> |
| <p>Licensed under the Apache <a href="https://www.apache.org/licenses/">license</a>, version 2.0</p> |
| <div style='max-width: 40em; margin: 0 auto'> |
| <p>Apache, Apache NetBeans, NetBeans, the Apache feather logo and the Apache NetBeans logo are trademarks of <a href="https://www.apache.org">The Apache Software Foundation</a>.</p> |
| <p>Oracle and Java are registered trademarks of Oracle and/or its affiliates.</p> |
| <p>The Apache NetBeans website conforms to the <a href="https://privacy.apache.org/policies/privacy-policy-public.html">Apache Software Foundation Privacy Policy</a></p> |
| </div> |
| </div> |
| </div> |
| |
| |
| <script src="../../../../_/js/vendor/lunr.js"></script> |
| <script src="../../../../_/js/search-ui.js" id="search-ui-script" data-site-root-path="../../../.." data-snippet-length="100" data-stylesheet="../../../../_/css/search.css"></script> |
| <script async src="../../../../search-index.js"></script> |
| <script src="../../../../_/js/vendor/jquery.min.js"></script> |
| <script src="../../../../_/js/vendor/what-input.min.js"></script> |
| <script src="../../../../_/js/vendor/foundation.min.js"></script> |
| <script src="../../../../_/js/vendor/jquery.colorbox-min.js"></script> |
| <script src="../../../../_/js/netbeans.js"></script> |
| <script> |
| $(function(){ $(document).foundation(); }); |
| </script> |
| <script src="../../../../_/js/vendor/highlight.min.js"></script> |
| <script> |
| document.addEventListener('DOMContentLoaded', (event) => { |
| document.querySelectorAll('pre code').forEach((el) => { |
| hljs.highlightElement(el); |
| }); |
| }); |
| </script> |
| </body> |
| </html> |