blob: 5462a473a2ab2ee5830028785d95c7bf9e2143ee [file] [log] [blame]
//
// 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.
//
= Using Oracle Java SE Embedded Support in NetBeans IDE
:jbake-type: tutorial
:jbake-tags: tutorials
:jbake-status: published
:syntax: true
:icons: font
:source-highlighter: pygments
:toc: left
:toc-title:
:description: Using Oracle Java SE Embedded Support in NetBeans IDE - Apache NetBeans
:keywords: Apache NetBeans, Tutorials, Using Oracle Java SE Embedded Support in NetBeans IDE
link:http://www.oracle.com/technetwork/java/embedded/overview/javase/index.html[+Oracle Java Standard Edition Embedded+] (Oracle Java SE Embedded) enables users to develop highly functional, reliable and portable applications for powerful embedded systems. NetBeans IDE supports Java SE Embedded features, such as footprint, memory, power, platform support, etc.
In this tutorial, you will learn how to get started with Java SE Embedded in NetBeans IDE and how to use the IDE support for Java SE Embedded.
== Setting Up a Remote Platform in NetBeans IDE
Once link:http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html?ssSourceSiteId=otncn[+Oracle Java SE Embedded+] runtime is downloaded and installed on your remote machine (Raspberry Pi is used for demonstration purposes in this tutorial), you need to set up NetBeans IDE with the remote platform as follows:
* activate the Java SE feature in NetBeans IDE
* install a remote Java SE platform in NetBeans IDE
NOTE: The remote operating system must be UNIX. Windows is not supported.
*To activate the Java SE feature in the IDE:*
1. Choose Tools > Plugins from the main IDE's toolbar.
2. In the Plugins dialog box, click the Installed tab and select Java SE in the list of available features.
[.feature]
--
image::images/plugins-small.png[role="left", link="images/plugins.png"]
--
. Click Activate.
. At the Welcome panel of the Installer dialog box, click Activate.
. When the activation is successfully completed, click Finish.
. Click Close to close the Plugins dialog box.
*To install a remote Java SE platform in NetBeans IDE:*
1. Choose Tools > Java Platforms.
The Java Platform Manager dialog box displays.
[.feature]
--
image::images/jpmanager-small.png[role="left", link="images/jpmanager.png"]
--
. Click Add Platform.
. In the Select Platform Type of the Add Java Platform wizard, select Remote Java Standard Edition and click Next.
The IDE displays the Add Java Platform dialog box.
[.feature]
--
image::images/addjp-small.png[role="left", link="images/addjp.png"]
--
. Specify the remote platform details such as the name, the IP address or DNS name of the device, login, password, and the path to the JRE on the remote device.
NOTE: The target operating system must be UNIX (Windows is not supported).
. Click Finish. The IDE validates the remote JRE by executing a probe and downloads the remote JRE system properties.
A new remote Java SE platform displays in the Java Platform Manager dialog box.
[.feature]
--
image::images/jpremote-small.png[role="left", link="images/jpremote.png"]
--
Now your NetBeans IDE is set up for remote Java SE development.
== Creating and Running a Project in the IDE
Now let us create a project that is going to be first run in the IDE and then on the remote platform.
*To create a project:*
1. In the IDE, choose File > New Project.
2. In the New Project wizard, choose the Java category and select Java Application in the Projects list. Click Next.
3. In the Name and Location page of the wizard, do the following:
* In the Project Name field, type `EmbeddedCalculator`.
* Leave the Use Dedicated Folder for Storing Libraries checkbox unselected.
* In the Create Main Class field, type `embeddedcalculator.EmbeddedCalculator`.
[.feature]
--
image::images/wizard-small.png[role="left", link="images/wizard.png"]
--
. Click Finish.
The IDE creates and opens the Java SE project in the Projects window.
. Replace the ``// TODO code application logic here`` line with the following code:
[source,java]
----
int a = 1;
int b = 2;
int c = a + b;
System.out.println (c);
----
. Save your changes by choosing File > Save.
To test your application, right-click the project name and choose Run from the context menu. The calculated output can be viewed in the Output window (Window > Output).
image::images/run-ide.png[]
=== Configuring a Project to Use a Remote Platform
To develop a Java SE embedded application on a remote platform using link:http://openjdk.java.net/jeps/161[+compact1, compact2, or compact3 runtime platforms+], JDK 8 needs to be registered in the IDE.
*To enable JDK 8 support in NetBeans IDE:*
1. In the IDE, choose Tools > Java Platforms from the main menu.
2. Click Add Platform in the Java Platform Manager dialog.
3. In the Add Java Platform dialog, select Java Standard Edition and click Next.
4. Specify the directory that contains the JDK and click Next.
[.feature]
--
image::images/jdk8-small.png[role="left", link="images/jdk8.png"]
--
. Verify that the default locations of the platform sources zip file and API documentation are valid. Click Finish to close the Add Java Platform dialog box.
JDK 8 is registered as a platform in the IDE.
[.feature]
--
image::images/jdk8registered-small.png[role="left", link="images/jdk8registered.png"]
--
. Click Close.
*To configure your project to use JDK 8:*
1. Right-click the EmbeddedCalculator project in the Projects window and select Properties from the context menu.
2. In the Project Properties dialog box, choose the Libraries category and set JDK 1.8 as the Java Platform.
[.feature]
--
image::images/prj-jdk8-small.png[role="left", link="images/prj-jdk8.png"]
--
. Select the Sources category and set Source/Binary Format to JDK 8.
[.feature]
--
image::images/prj-source-jdk8-small.png[role="left", link="images/prj-source-jdk8.png"]
--
. Specify the profile that is used as runtime on a remote platform (for example, Compact 2).
[.feature]
--
image::images/prj-jdk8-profile-small.png[role="left", link="images/prj-jdk8-profile.png"]
--
. Click OK to save the changes.
Your project is set to recognize a particular runtime on a remote platform.
== Running a Project on a Remote Platfrom
You can run and debug the application on a remote device after setting the project configuration to a configuration different from the default one.
*To create a new configuration:*
1. Right-click the project name in the Projects window and select Properties from the context menu.
2. Choose the Run category.
3. Click New to the right of the Configuration drop-down list.
4. In the Create New Configuration dalog box, specify the name of a new configuration and click OK.
5. Select the runtime platform name in the Runtime Platform drop-down list.
[.feature]
--
image::images/config-runtime-small.png[role="left", link="images/config-runtime.png"]
--
. Click OK to save your edits.
If you run the project on a remote platform (Run > Run Project (project name)), the output will look similar to what is shown in the figure below.
[.feature]
--
image::images/run-remote-small.png[role="left", link="images/run-remote.png"]
--
*To switch between project configurations:*
* Choose Run > Set Project Configuration > configuration name or right-click the project name and choose Set Configuration > configuration name from the context menu.
[.feature]
--
image::images/switch-config-small.png[role="left", link="images/switch-config.png"]
--