Showing posts with label Netbeans. Show all posts
Showing posts with label Netbeans. Show all posts

Friday, November 13, 2015

Download and Install Netbeans IDE 8.1 on Raspberry Pi 2/Raspbian Jessie

Netbeans IDE 8.1 run on Raspberry Pi 2/Raspbian Jessie
To download and install Netbeans IDE 8.1 for Raspberry Pi 2/Raspbian Jessie:
  • Visit netbeans.org,  download NetBeans IDE 8.1 for platform of OS Independent Zip.
  • After the download of the platform-independent ZIP file completes, extract it to any folder on your system.
  • Switch to the /netbeans/bin, run ./netbeans
(reference: https://netbeans.org/community/releases/81/install.html#install_zip)


Saturday, October 17, 2015

Remote develop C/C++ program from Windows 10, run on Raspberry Pi, using NetBeans IDE

This post show how to develop C/C++ program on Netbeans IDE run on Windows 10, set up remote host on raspberry Pi. Such that you can run the program on Raspberry Pi remotely.




Local client host (the PC you used to develop):
Windows 10
Netbeans IDE 8.0.2 with C/C++ plugins (https://netbeans.org/community/releases/80/cpp-setup-instructions.html#downloading)
C/C++ compiler: 32-bit MinGW(https://netbeans.org/community/releases/80/cpp-setup-instructions.html#mingw)

Remote host (The target remote platform to run the program):
Raspberry Pi 2
Raspbian Jessie (2015-09-24)

Follow the steps in the video:



Test code, C++:
#include <iostream>

using namespace std;

int main(int argc, char** argv) {

    std::cout << "Hello World!\n";
    
#ifdef __linux__
    std::cout << "__linux__\n";
#elif defined(__unix__)
    std::cout << "__unix__\n";
#elif defined(_WIN64)
    std::cout << "Windows 64\n";
#elif defined(_WIN32)
    std::cout << "Windows 32\n";
#endif

#if __WORDSIZE == 64
    std::cout << "64 bit\n";
#else
    std::cout << "32 bit\n";
#endif

    return 0;
}

Reference:
- https://netbeans.org/kb/docs/cnd/remote-modes.html
- https://netbeans.org/kb/docs/cnd/remotedev-tutorial.html#setup

Related:
- Remote run JavaFX on Raspbian Jessie, from Netbeans/Windows 10


Saturday, October 3, 2015

Thursday, September 10, 2015

Remote run Java on Raspberry Pi, host from NetBeans on Windows 10

This video show how to develop Java application with NetBeans IDE 8.0.2 running on Windows 10, create Remote Java SE platform, remote run/debug on Raspberry Pi/Raspbian Wheezy .




The following java code list system by calling System.getProperties().
package javaapplication14;

import java.util.Enumeration;
import java.util.Properties;

public class JavaApplication14 {

    public static void main(String[] args) {

        System.out.println("\nSystem Properties\n");
        System.out.println("=================\n");
        
        Properties properties = System.getProperties();
        System.out.println(properties.toString());
        System.out.println("\n");

        Enumeration<String> prop
                = (Enumeration<String>) properties.propertyNames();

        while (prop.hasMoreElements()) {
            String propName = prop.nextElement();
            System.out.println(
                    propName + " : "
                    + System.getProperty(propName));
        }
    }

}


How it run on Windows 10/Intel i5 vs Raspbian/Raspberry Pi 2.




Updated@2015-10-04: Appliable on Raspbian Jessie.

Saturday, April 11, 2015

Read dweet.io JSON using Java, develop and run on Raspberry Pi

I have a previous exercise of "Python to send data to Cloud". It can be viewed on browser at: http://dweet.io/follow/helloRaspberryPi_RPi2_vcgencmd.


Or read the dweets in JSON at: https://dweet.io/get/dweets/for/helloRaspberryPi_RPi2_vcgencmd
(Note that dweet.io only holds on to the last 500 dweets over a 24 hour period. If the thing hasn't dweeted in the last 24 hours, its history will be removed.)


Here is a Java exercise to parse the dweets JSON, develop and run on Raspberry Pi 2 with Netbeans IDE. Suppose it can run on any other Java SE supported platform.

JavaDweetIO.java
package javadweetio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JavaDweetIO {

    public static void main(String[] args) {
        
        String myThing = "helloRaspberryPi_RPi2_vcgencmd";
        try {
            JSONObject json = 
                ReadJSON("http://dweet.io/get/dweets/for/" + myThing);

            JSONArray jsonArray_with = json.getJSONArray("with");
            
            for(int i=0; i<jsonArray_with.length(); i++){
                JSONObject jsonObject_with = (JSONObject) jsonArray_with.get(i);
                String created = jsonObject_with.getString("created");
                JSONObject jsonObject_with_content = 
                    jsonObject_with.getJSONObject("content");
                Double RaspberryPi2_core_temp = 
                    jsonObject_with_content.getDouble("RaspberryPi2_core_temp");
                
                System.out.println(created);
                System.out.println(RaspberryPi2_core_temp);
                System.out.println("-----");
            }
            
        } catch (IOException | JSONException e){
            System.out.println(e.toString());
        }
    }

    public static JSONObject ReadJSON(String url) 
            throws IOException, JSONException {
        
        try (InputStream inputStream = new URL(url).openStream()) {
            InputStreamReader inputStreamReader = 
                new InputStreamReader(inputStream, Charset.forName("UTF-8"));
            BufferedReader bufferedReader = 
                new BufferedReader(inputStreamReader);

            StringBuilder jsonBody = new StringBuilder();
            int singleChar;
            while ((singleChar = bufferedReader.read()) != -1) {
                jsonBody.append((char)singleChar);
            }

            JSONObject json = new JSONObject(jsonBody.toString());
            return json;
        }
    }
}


To import org.json in our Java code, we have to Add org.json library, java-json.jar, to NetBeans Java project.




If you want check the JSON online, before you parse it, you can try: http://jsonlint.com/



Add org.json library, java-json.jar, to NetBeans Java project. Run on Raspberry Pi

In next example, I will retrieve my dweet.io thing in JSON format. I will use JSON in Java (org.json) to parse JSON. The java-json.jar can be download here: http://www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm

This video show how to download and add java-json.jar (org.json) to Netbeans Java project, run on Raspberry Pi 2/Raspbian. Suppose it is same in NetBeans run on other platforms.

Monday, March 30, 2015

Java get CPU frequency by "cat /sys/.../scaling_cur_freq"

This example show Java program to get CPU frequency with Linux command "cat /sys/devices/system/cpu/cpu#/cpufreq/scaling_cur_freq", where # is the cpus' number.



Last post show a Python version to get CPU frequency, and the post in my another blog show a Android version. Here is a Java SE version.

JavaRead_scaling_cur_freq.java
package javaread_scaling_cur_freq;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

public class JavaRead_scaling_cur_freq {

    public static void main(String[] args) {
        readCpuFreqNow();
    }

    static private void readCpuFreqNow() {
        File[] cpuFiles = getCPUs();
        System.out.println("number of cpu: " + cpuFiles.length);

        for (File cpuFile : cpuFiles) {
            String path_scaling_cur_freq 
                = cpuFile.getAbsolutePath() + "/cpufreq/scaling_cur_freq";
            System.out.println(path_scaling_cur_freq);
            System.out.println(cmdCat(path_scaling_cur_freq));
        }

    }
    
    //run Linux command 
    //$ cat f
    static private String cmdCat(String path){
        StringBuilder stringBuilder = new StringBuilder();
        
        Process process;
        try {
            process = Runtime.getRuntime().exec("cat " + path);
            process.waitFor();
            
            BufferedReader reader = 
                new BufferedReader(new InputStreamReader(process.getInputStream()));
            
            String line;   
            while ((line = reader.readLine())!= null) {
                stringBuilder.append(line).append("\n");
            }
            
        } catch (IOException | InterruptedException ex) {
            Logger.getLogger(JavaRead_scaling_cur_freq.class
                .getName()).log(Level.SEVERE, null, ex);
        }

        return stringBuilder.toString();
    }

    /*
     * Get file list of the pattern
     * /sys/devices/system/cpu/cpu[0..9]
     */
    static private File[] getCPUs() {

        class CpuFilter implements FileFilter {

            @Override
            public boolean accept(File pathname) {
                return Pattern.matches("cpu[0-9]+", pathname.getName());
            }
        }

        File dir = new File("/sys/devices/system/cpu/");
        File[] files = dir.listFiles(new CpuFilter());
        return files;
    }

}


This video show the code build on Raspberry Pi 2 using NetBeans IDE.



The code work on other Linux also, such as Ubuntu. This video show the jar build on Raspberry Pi 2, copy to Ubuntu Linux and run directly.




Related:
- Install NetBeans IDE on Raspberry Pi 2/Raspbian, to program using Java

Sunday, March 22, 2015

Install C/C++ plugins for NetBeans on Raspberry Pi 2/Raspbian

It is assumed you have NetBeans 8.0.2 installed on your Raspberry Pi 2/Raspbian. By installing C/C++ plugins to NetBeans IDE, you can develop in C/C++.


- Click Tools -> Plugins
- Select Available Plugins tab
- Search C/C++, and check it.
- Click Install


Install NetBeans IDE on Raspberry Pi 2/Raspbian, to program using Java

NetBeans IDE is the official IDE for Java 8. With quad-core ARM Cortex-A7 CPU on Raspberry Pi 2, pre-loaded Java 8 on Raspbian, it's easy to install NetBeans 8 on Raspberry Pi.


Visit NetBeans Download page (https://netbeans.org/downloads/), select Platform of OS Independent Zip, download and un-zip to any folder you want.

Switch to the unzipped /netbeans/bin folder, run the executable file netbeans:
$ ./netbeans

This video show how to download and install NetBeans IDE 8.0.2 on Raspberry Pi 2.



It is seem JavaFX not supported currently




x Error of failed request: BadMatch (invalid parameter attributes)

In the above demo video, I log-in Raspberry Pi 2 remotely with xrdp run on RPi 2, and remmina (Remote Desktop Client) on another PC running Ubuntu Linux.

Originally, I set Color depth of High color (15 bpp), it work once only. After then, I run netbeans next time, it fail with following error:

x Error of failed request: BadMatch (invalid parameter attributes)
  Major opcode of failed request: 72 (x_PutImage)
  Serial number of failed request: 51
  Current serial number in output stream: 55

To fix it in my case, set Color depth of High color (16 bpp).



Next:
- Install C/C++ plugins for NetBeans on Raspberry Pi 2/Raspbian

Related:
- A example of Java to get CPU frequency, build with NetBeans on Raspberry Pi, the jar run on other Linux machine also.

Tuesday, September 16, 2014

Saturday, September 6, 2014

java-google-translate-text-to-speech, unofficial API for Google Translate in Java.

java-google-translate-text-to-speech is API unofficial with the main features of Google Translate in Java. I will add text-to-speech (tts) function in my next Yahoo Weather exercise.

This video show how to download jars, and add library to Netbeans Java project.

Friday, September 5, 2014

Download and add Apache HttpComponents jar to Netbeans Project

In the coming post, I have to use Apache HttpComponents jar in my code. The Apache HttpComponents™ project is responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols.

It can be download here: http://hc.apache.org/.

This video show how to download and add the Apache HttpComponents jar to your project in Netbeans.

Wednesday, September 3, 2014

Java serial communication with Arduino Uno with jSSC, on Raspberry Pi

jSSC (Java Simple Serial Connector) - library for working with serial ports from Java. jSSC support Win32(Win98-Win8), Win64, Linux(x86, x86-64, ARM), Solaris(x86, x86-64), Mac OS X 10.5 and higher(x86, x86-64, PPC, PPC64).

This post show a Java program run on Raspberry Pi, using jSSC library, to send message to USB connected Arduino Uno board.


The development platform is a PC running Ubuntu with Netbeans 8, and deploy the program to Raspberry Pi remotely.

- To add jSSC library to our Netbeans Java project, read the post "Install and test java-simple-serial-connector with Arduino".

- The program code is almost same as the code on the page. With 3 seconds delay after serialPort.openPort(), to wait Automatic (Software) Reset on Arduino Uno board.
package java_jssc_uno;

import java.util.logging.Level;
import java.util.logging.Logger;
import jssc.SerialPort;
import jssc.SerialPortException;

public class Java_jSSC_Uno {

    public static void main(String[] args) {
        SerialPort serialPort = new SerialPort("/dev/ttyACM0");
        try {
            System.out.println("Port opened: " + serialPort.openPort());

            try {
                Thread.sleep(3000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Java_jSSC_Uno.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
            System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("Java_jSSC_Uno".getBytes()));
            System.out.println("Port closed: " + serialPort.closePort());
        }
        catch (SerialPortException ex){
            System.out.println(ex);
        }
    }
    
}

- To deploy to Raspberry Pi remotely with Netbeans 8, refer to the post "Set up Java SE 8 Remote Platform on Netbeans 8 for Raspberry Pi".


For the sketch (and extra info) on Arduino Uno, read the post in my Arduino blog.


Sunday, August 10, 2014

Cross compile Java/Swing program for Raspberry Pi, with Netbeans 8

This video show how to cross compile Java/Swing program for Raspberry Pi, on PC running Netbeans.



Currently, I cannot remote run the Java/Swing program on Raspberry Pi within Netbeans IDE, caused by "No X11 DISPLAY variable was set, but this program performed an operation which requires it". But it can create the runnable jar in Raspberry Pi. You can login Raspberry Pi and run the jar locally.

You need to:
- Install JDK 8 on Raspberry Pi
- Set up Java SE 8 Remote Platform on Netbeans 8 for Raspberry Pi
- and know how to Run/Build JavaFX application on Raspberry Pi remotely from Netbeans 8

Code of this example:
package helloworldswing;

import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class HelloWorldSwing {

    private static void createAndShowGUI() {

        JFrame frame = new JFrame("Hello Swing@Raspberry Pi");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setPreferredSize(new Dimension(400, 300));

        JLabel label = new JLabel();
        label.setText(
            "Hello: " 
            + System.getProperty("os.arch") + "/"
            + System.getProperty("os.name"));
        
        frame.getContentPane().add(label);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
    
}



Updated@2015-12-06: Solution of "No X11 DISPLAY variable was set, but this program performed an operation which requires it":

Refer to karczas' comment in YouTube video, The solution of 0:50 error (No X11 DISPLAY variable was set, but this program performed an operation which requires it) which will allow you to run and debug GUI application directly from NetBeans and display their content on your RaspPi (or BeagleBone Black): 
https://mkarczewski.wordpress.com/2015/12/05/netbeans-remote-java-arm-debugging-with-gui



Remote debug Java program on Raspberry Pi using Netbeans 8

With JDK 8 installed on Raspberry Pi, and Set up Java SE 8 Remote Platform on Netbeans 8, you can Run JavaFX application on Raspberry Pi remotely from Netbeans 8, and also debug Java/JavaFX program running on Raspberry Pi remotely on PC with Netbeans 8.

This video show how to debug the last example "Java/JavaFX Client run on Raspberry Pi, link with Android Server" remotely with Netbeans 8.

Java/JavaFX Client run on Raspberry Pi, link with Android Server

It's the Java/JavaFX version of Android client run on Raspberry Pi (via Netbeans 8 Remote Platform), to link with Android Server.

In the video, the VLC Media Player display is the Raspberry Pi RCA video captured with USB Video Adapter.

The program code can be found here:
- Java/JavaFX version of Android client
- Android Server

To know how to:
- Set up Java SE 8 Remote Platform on Netbeans 8 for Raspberry Pi
- Run JavaFX application on Raspberry Pi remotely from Netbeans 8


Sunday, August 3, 2014

Run JavaFX application on Raspberry Pi remotely from Netbeans 8

With Remote Platform set up on Netbeans 8, we can also develop JavaFX application on host computer running Netbeans, run the application remotely on Raspberry Pi. In case of Java FX application running on Raspberry Pi, it will display on Raspberry Pi monitor, instead of console.

Set up Java SE 8 Remote Platform on Netbeans 8 for Raspberry Pi

With Netbeans 8 installed on host computer and Java SE 8 on Raspberry Pi, we can set up remote platform on Netbeans 8. Such that we can develop Java application using Netbeans on host and deploy on Raspberry Pi remotely, all within Netbeans IDE.

It's assumed Java SE 8 have been installed on your Raspberry Pi as in last post "Install JDK 8 on Raspberry Pi and set JAVA_HOME and PATH".

In host PC (Ubuntu in my case) start Netbeans 8.

Click Tools -> Java Platforms

Click Add Platform...


Select Remote Java Standard Edition and click Next >


Name your new Remote Platform, and enter other information:
- 192.168.1.104 is the IP address of your remote Raspberry Pi.
- pi, the user in Raspberry Pi, and also enter password.
- /opt/jdk1.8.0_06 in Remote JRE Path is the JDK 8 installed location on Raspberry Pi, in last post.

(Updated@2014-09-17) for New Raspbian (2014-09-09) come with Java 8, set Remote JRE Path to default location /usr. ~ Setup Netbeans Remote Platform for default Java 8 in new Raspbian

Then finish.



This video show the steps:


Deploy Java application on Raspberry Pi remotely from Netbeans 8

Create Java Application in Netbeans as normal case. To Run it using the Remote Platform (created in previous steps):

Right click on Project -> Propertiers.

Select Run tab. Select the new created Remote Platform in Runtime Platform, and name the new Configuration.


Then you can run the application on remote Raspberry Pi by running it in this new configuration.



Once Remote Platform setup in your Netbeans IDE, you can also
- development JavaFX application on Nerbeans 8, and run it remotely on Raspberry Pi
- remote debug Java program on Raspberry Pi
- Cross compile Java/Swing program for Raspberry Pi