Česky   |  Deutsch   |  English   |  Español   |  Français   |  Indonesia   |  日本語   |  한글   |  Polski   |  Português (BR)   |  Türkçe   |  中文   |  正體中文   |  Your Language  
PlanetNetbeans
Planet NetBeans is an aggregation of NetBeans related musings from all over the Blogosphere.
Feeds
[RSS 1.0 Feed] [RSS 2.0 Feed]
[FOAF Subscriptions] [OPML Subscriptions]
Do you blog about NetBeans ? Add your blog to PlanetNetBeans.
Feed Subscriptions
NetBeans Zone - The social network for developers (feed)
APIDesign - Blogs (feed)
David R. Heffelfinger (feed)
Carsten Zerbst's Weblog (feed)
Winston Prakash's Weblog (feed)
Java, business and... NetBeans ! [[ Jonathan Lermitage ]] - NetBeans IDE (feed)
Need to find a title (feed)
Roger Searjeant's blog (feed)
Optonline Webmail (feed)
Michael's blog » NetBeans (feed)
DukeScript (feed)
ProNetBeans (feed)
Paulo Canedo » NetBeans English (feed)
Bistro! 2.0 (feed)
Anuradha (feed)
Netbeans6/6.5 my best practices (feed)
Java Evangelist John Yeary's Blog (feed)
Neil's Dev Stuff (feed)
Category: NetBeans | Software and Science (feed)
Computer says null; (feed)
NetBeans Adventures, Java and more (feed)
Allan Lykke Christensen » NetBeans (feed)
Inspiration and Expression » Netbeans (feed)
open source. open mind. (feed)
John O'Conner » NetBeans (feed)
Koberoi Oracle (feed)
Adam Bien (feed)
Ignacio Sánchez Ginés » NetBeans (feed)
Bernhard's Weblog (feed)
Michel Graciano's Weblog (feed)
Ramon.Ramos (feed)
Ozone and Programming » netbeans (feed)
NetBeans Ruminations » NetBeans (feed)
Tiplite » netbeans (feed)
Arun Gupta, Miles to go ... (feed)
Geertjan's Blog (feed)
.JARa's Bilingual Weblog (feed)
JavaFX Composer (feed)
The Java Jungle (feed)
Jesse Glick (feed)
Martin Grebac (feed)
The NetBeans Community Podcast (feed)
NetBeans Profiler (feed)
NetBeans for PHP (feed)
NetBeans Web Client (feed)
Rechtacek's (feed)
Virtual Steve (feed)
My First Blog - Satyajit Tripathi (feed)
The Aquarium (feed)
Tinuola Awopetu (feed)
Insert Witty Irony Here (feed)
mkleint (feed)
NetBeans Community Docs Blog (feed)
The Netbeans Experience (feed)
NbPython/ jpydbg / pymvs (feed)
Shanbag's Blog (ರಜತ ಲೋಕ) (feed)
Wade Chandler's Programming Blog (feed)
Devlin's Lab (feed)
Big Al's Blog (feed)
Code Snakes (feed)
In perfect (spherical) shape (feed)
Van Couvering Is Not a Verb (feed)
Diego Torres Milano's blog (feed)
Vroom Framework (feed)
Messages from mrhaki (feed)
Jeff's Blog (feed)
Oliver Wahlen's Blog (feed)
Shuttle between Galaxies (feed)
Welcome to my live... (feed)
Netbeans IDE Blog by Tushar Joshi, Nagpur (feed)
Devel Blog (feed)
diamond-powder (feed)
Manikantan's Netbeans (feed)
Antonio's blog (feed)
Where's my Blog?!

Powered by:    Planet

Last updated:
January 29, 2015 03:05 PM
All times are UTC

Sponsored by
sponsored by Oracle

visit NetBeans website
NetBeans Zone - The social network for developers - January 27, 2015 08:58 PM
Agenda: NetBeans Day Netherlands

NetBeans Day Netherlands, to be held on Thursday, 12 February, is filling up fast. However, there's certainly still space to attend. You, and your friends, colleagues, fellow students, including teachers in the software development domain, are warmly invited to attend this free, unique, and action packed day. Sign up for the event...

DukeScript - January 27, 2015 11:53 AM
Type-safe JSON Parsing. Easy with DukeScript!

DukeScript is primarily optimized for designing client side responsive applications in Java and HTML, however libraries in its core are built with the goal of making Java/JavaScript interoperability easier. One of the essential concepts in JavaScript is JSON. Thus it is no surprise, DukeScript makes processing JSON from Java really smooth.

Where is My JSON?

First of all we need to obtain a JSON file. One of the free JSON services is the GitHub REST API, so let’s use it. The following command lists all repositories for a github account (actually the Jersey JAX-RS developers account):

$ curl https://api.github.com/users/jersey/repos

The ouput of this query has the following format. Save it into a file and let’s design a type-safe way to parse such a file with the help of DukeScript:

[
  {
    "id": 6109440,
    "name": "hol-sse-websocket",
    "full_name": "jersey/hol-sse-websocket",
    "owner": {
      "login": "jersey",
      "id": 399710,
      "avatar_url": "https://avatars.githubusercontent.com/u/399710?v=3",
      "gravatar_id": "",
      "url": "https://api.github.com/users/jersey",
      "html_url": "https://github.com/jersey",
      "followers_url": "https://api.github.com/users/jersey/followers",
      "following_url": "https://api.github.com/users/jersey/following{/other_user}",
      "gists_url": "https://api.github.com/users/jersey/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/jersey/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/jersey/subscriptions",
      "organizations_url": "https://api.github.com/users/jersey/orgs",
      "repos_url": "https://api.github.com/users/jersey/repos",
      "events_url": "https://api.github.com/users/jersey/events{/privacy}",
      "received_events_url": "https://api.github.com/users/jersey/received_events",
      "type": "Organization",
      "site_admin": false
    },
    "private": false,
    "html_url": "https://github.com/jersey/hol-sse-websocket",
    "description": "Hands-on-lab on using server-sent events and web socket with Jersey and Tyrus.",
    "fork": false,
    "url": "https://api.github.com/repos/jersey/hol-sse-websocket",
    "forks_url": "https://api.github.com/repos/jersey/hol-sse-websocket/forks",
    "keys_url": "https://api.github.com/repos/jersey/hol-sse-websocket/keys{/key_id}",
    "collaborators_url": "https://api.github.com/repos/jersey/hol-sse-websocket/collaborators{/collaborator}",
    "teams_url": "https://api.github.com/repos/jersey/hol-sse-websocket/teams",
    "hooks_url": "https://api.github.com/repos/jersey/hol-sse-websocket/hooks",
    "issue_events_url": "https://api.github.com/repos/jersey/hol-sse-websocket/issues/events{/number}",
    "events_url": "https://api.github.com/repos/jersey/hol-sse-websocket/events",
    "assignees_url": "https://api.github.com/repos/jersey/hol-sse-websocket/assignees{/user}",
    "branches_url": "https://api.github.com/repos/jersey/hol-sse-websocket/branches{/branch}",
    "tags_url": "https://api.github.com/repos/jersey/hol-sse-websocket/tags",
    "blobs_url": "https://api.github.com/repos/jersey/hol-sse-websocket/git/blobs{/sha}",
    "git_tags_url": "https://api.github.com/repos/jersey/hol-sse-websocket/git/tags{/sha}",
    "git_refs_url": "https://api.github.com/repos/jersey/hol-sse-websocket/git/refs{/sha}",
    "trees_url": "https://api.github.com/repos/jersey/hol-sse-websocket/git/trees{/sha}",
    "statuses_url": "https://api.github.com/repos/jersey/hol-sse-websocket/statuses/{sha}",
    "languages_url": "https://api.github.com/repos/jersey/hol-sse-websocket/languages",
    "stargazers_url": "https://api.github.com/repos/jersey/hol-sse-websocket/stargazers",
    "contributors_url": "https://api.github.com/repos/jersey/hol-sse-websocket/contributors",
    "subscribers_url": "https://api.github.com/repos/jersey/hol-sse-websocket/subscribers",
    "subscription_url": "https://api.github.com/repos/jersey/hol-sse-websocket/subscription",
    "commits_url": "https://api.github.com/repos/jersey/hol-sse-websocket/commits{/sha}",
    "git_commits_url": "https://api.github.com/repos/jersey/hol-sse-websocket/git/commits{/sha}",
    "comments_url": "https://api.github.com/repos/jersey/hol-sse-websocket/comments{/number}",
    "issue_comment_url": "https://api.github.com/repos/jersey/hol-sse-websocket/issues/comments/{number}",
    "contents_url": "https://api.github.com/repos/jersey/hol-sse-websocket/contents/{+path}",
    "compare_url": "https://api.github.com/repos/jersey/hol-sse-websocket/compare/{base}...{head}",
    "merges_url": "https://api.github.com/repos/jersey/hol-sse-websocket/merges",
    "archive_url": "https://api.github.com/repos/jersey/hol-sse-websocket/{archive_format}{/ref}",
    "downloads_url": "https://api.github.com/repos/jersey/hol-sse-websocket/downloads",
    "issues_url": "https://api.github.com/repos/jersey/hol-sse-websocket/issues{/number}",
    "pulls_url": "https://api.github.com/repos/jersey/hol-sse-websocket/pulls{/number}",
    "milestones_url": "https://api.github.com/repos/jersey/hol-sse-websocket/milestones{/number}",
    "notifications_url": "https://api.github.com/repos/jersey/hol-sse-websocket/notifications{?since,all,participating}",
    "labels_url": "https://api.github.com/repos/jersey/hol-sse-websocket/labels{/name}",
    "releases_url": "https://api.github.com/repos/jersey/hol-sse-websocket/releases{/id}",
    "created_at": "2012-10-07T04:44:32Z",
    "updated_at": "2014-06-29T22:29:42Z",
    "pushed_at": "2013-05-29T16:56:03Z",
    "git_url": "git://github.com/jersey/hol-sse-websocket.git",
    "ssh_url": "git@github.com:jersey/hol-sse-websocket.git",
    "clone_url": "https://github.com/jersey/hol-sse-websocket.git",
    "svn_url": "https://github.com/jersey/hol-sse-websocket",
    "homepage": null,
    "size": 7750,
    "stargazers_count": 11,
    "watchers_count": 11,
    "language": "Java",
    "has_issues": true,
    "has_downloads": true,
    "has_wiki": true,
    "has_pages": false,
    "forks_count": 5,
    "mirror_url": null,
    "open_issues_count": 1,
    "forks": 5,
    "open_issues": 1,
    "watchers": 11,
    "default_branch": "master"
  },
  {
     "etc." : "etc."
  }
]

Setting the Project Up

Let’s get started following the same way we start with regular HTML UI based DukeScript application. Follow the getting started tutorial if you are OK with using NetBeans. If you want to stay on command line, you can use:

$ mvn archetype:generate -DarchetypeGroupId=org.apidesign.html \
  -DarchetypeArtifactId=knockout4j-archetype \
  -DarchetypeVersion=1.1.2

Once our application is generated, we can start modifying the sample application to avoid displaying the UI, but rather parse our JSON file. Let’s remove:

  • src/main/webapp/pages/index.html - no UI definitions
  • src/main/java/your/pkg/DataModel.java - no UI model
  • src/test - we don’t need tests for this simple sample

The next step is to change dependencies in our pom.xml - the sample project can parse JSON inside of a running browser, but we want to do it in Java. Luckily there is a JAR that can handle that. Just include it on runtime classpath and it will handle all the parsing for us. Add the following dependency:

<dependency>
  <groupId>org.netbeans.html</groupId>
  <artifactId>ko-ws-tyrus</artifactId>
  <version>${net.java.html.version}</version>
  <scope>runtime</scope>
</dependency>

In addition to that let’s clean the Main.java so it is ready for our parsing code and looks like:

package your.pkg;

public final class Main {
    private Main() {
    }
    
    public static void main(String... args) throws Exception {
    }
}

Now we have an empty skeletal application what we can use to do the parsing, which can be verified by executing ‘mvn clean install’ - the project should built without any issues.

Parsing JSON Files

We are ready to start the parsing. There is the net.java.html.json.Models class in the core DukeScript API and it contains two overloaded variants of the method parse. One method can parse a single JSON object, the second can parse a JSON array of multiple JSON objects. Given the fact that the file we obtained from GitHub lists an array of repositories, we should use the more complicated variant. Here is the code:

public static void main(String... args) throws Exception {
    BrwsrCtx ctx = parsingContext();
    FileInputStream is = new FileInputStream("/tmp/jersey.json");
    List<RepositoryInfo> arr = new ArrayList<>();
    Models.parse(ctx, RepositoryInfo.class, is, arr);

    System.err.println("all parsed data: " + arr);

    RepositoryInfo first = arr.get(0);
    System.err.println("id: " + first.getId());

    is.close();
}

As part of the setup we get the parsing context. Then we open the JSON file we want to parse. We allocate an array to hold the results and then ask the parse method to do the parsing and fill the list. Then we print the whole array to output and also access the first element in the array in a type-safe way and obtain its id property. Here is the output from the execution of the above program:

all parsed data: [{"id":6109440}, {"id":4368712}, {"id":14029306}, {"id":4522462}, {"id":911627}]
id: 6109440

Now one important question: How does the code know there is an id property in the JSON?

Defining the Model

DukeScript core APIs support a type-safe way of accessing JSON structures. Moreover, in order to avoid writing tons of boiler-plate code, we describe the JSON structure using annotations and generate the rest with the help of annotation processors. As such the RepositoryInfo class is defined by:

@Model(className="RepositoryInfo", properties = {
    @Property(name = "id", type = int.class)
})
public final class Main {
   // now the main method
}

The above definition generates the RepositoryInfo class with a single integer property id and code to unmarshall JSON into instances of that class. The RepositoryInfo class also defines a reasonable toString() method - hence the whole list of such objects can be dumped into output in JSON format.

What to do when you want to parse other JSON properties? Take a look at the format of the downloaded JSON response file and add a new property definition! For example there is the name property which seems to be of type String. Just change the definition to:

@Model(className="RepositoryInfo", properties = {
    @Property(name = "id", type = int.class),
    @Property(name = "name", type = String.class),
})

Just by adding a single line, a getter getName() is added to the RepositoryInfo info class and you can use it in Java code:

RepositoryInfo first = arr.get(0);
System.err.println("id: " + first.getId());
System.err.println("name: " + first.getName());

The output when running the modified program is now:

all parsed data: [{"id":6109440,"name":"hol-sse-websocket"}, {"id":4368712,"name":"jersey"}, {"id":14029306,"name":"jersey-1.x"}, {"id":4522462,"name":"jersey-1.x-old"}, {"id":911627,"name":"jersey-old"}]
id: 6109440
name: hol-sse-websocket

And we can continue adding as many properties into our @Model definition as we need. For example one named private of type boolean. And so on, and so on, until we can access enough information via type-safe Java getters. The remaining, not listed, properties are silently ignored.

Parsing Nested Objects

We can see that the JSON format contains a nested object named owner. How can we parse such a structure in a type-safe way? Just define yet another model definition for it:

@Model(className="RepositoryInfo", properties = {
    @Property(name = "id", type = int.class),
    @Property(name = "name", type = String.class),
    @Property(name = "owner", type = Owner.class),
    @Property(name = "private", type = boolean.class),
})
public final class Main {
    @Model(className = "Owner", properties = {
        @Property(name = "login", type = String.class)
    })
    static final class OwnerCntrl {
    }
    // the main method...
}

With the above definition one can call getOwner().getLogin() to obtain the login information from a nested object. In addition to that, one can also access an array of values by specifying @Property(array = true, ...) when defining the JSON structure we want to access from Java. Here is the final code of our class:

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import net.java.html.BrwsrCtx;
import net.java.html.json.Model;
import net.java.html.json.Models;
import net.java.html.json.Property;
import org.netbeans.html.context.spi.Contexts;

@Model(className="RepositoryInfo", properties = {
    @Property(name = "id", type = int.class),
    @Property(name = "name", type = String.class),
    @Property(name = "owner", type = Owner.class),
    @Property(name = "private", type = boolean.class),
})
public final class Main {
    @Model(className = "Owner", properties = {
        @Property(name = "login", type = String.class)
    })
    static final class OwnerCntrl {
    }

    private Main() {
    }
    
    public static void main(String... args) throws Exception {
        BrwsrCtx ctx = parsingContext();
        FileInputStream is = new FileInputStream("/tmp/jersey.json");
        List<RepositoryInfo> arr = new ArrayList<>();
        Models.parse(ctx, RepositoryInfo.class, is, arr);

        System.err.println("all parsed data: " + arr);
        
        RepositoryInfo first = arr.get(0);
        System.err.println("id: " + first.getId());
        System.err.println("name: " + first.getName());
        System.err.println("private: " + first.isPrivate());
        System.err.println("owner.login: " + first.getOwner().getLogin());
    }
}

Here is the final output:

all parsed data: [{"id":6109440,"name":"hol-sse-websocket","owner":{"login":"jersey"},"private":false}, {"id":4368712,"name":"jersey","owner":{"login":"jersey"},"private":false}, {"id":14029306,"name":"jersey-1.x","owner":{"login":"jersey"},"private":false}, {"id":4522462,"name":"jersey-1.x-old","owner":{"login":"jersey"},"private":false}, {"id":911627,"name":"jersey-old","owner":{"login":"jersey"},"private":false}]
id: 6109440
name: hol-sse-websocket
private: false
owner.login: jersey

Parsing JSON in a type-safe way in Java has never been easier!

Appendix: Setting the Context

The last thing to mention is the way to setup our parsing context. It is a bit magical, but as it is done just once, when setting up the classpath of the whole application, it can be hidden, for example, in the following method:

private static BrwsrCtx parsingContext() {
    Contexts.Builder builder = Contexts.newBuilder("tyrus");
    Contexts.fillInByProviders(Main.class, builder);
    return builder.build();
}

What does it do? Well it uses the ‘magic string’ “tyrus” to request the Java implementation of JSON parser which is provided by the ‘ko-ws-tyrus’ module (that is the reason why we added a dependency on this module in our pom.xml).

This is exactly the kind of configuration done by Jersey Faces to register proper entity convertors, so one can use the classes generated by the @Model annotation inside of Jersey’s @GET, etc. methods just by including the appropriate method on the Jersey application classpath.

Once again, enjoy DukeScript everywhere!

Geertjan's Blog - January 26, 2015 08:00 AM
Exposing Yeoman Generators to NetBeans IDE

The plan is to, as shown below, show all of the Yeoman generators and let the user select the generator they want to use.

Above, all of them are shown, including those already installed. The next step is to distinguish those that are installed from those that are not. If an uninstalled generator is selected, it will automatically be installed via 'npm install -g', after which it will immediately be used. If it is already installed, it will simply be used when selected, after Next is clicked above, and a folder is specified.

The biggest problem at that point will be ensuring that the generator runs non-interactively. Or to enable the user to enter somehow the arguments and parameters requested by the selected generator. Finally, the generated application will then automatically be opened into NetBeans IDE when the Yeoman process completes.

Geertjan's Blog - January 23, 2015 10:35 PM
Processing Output on the Yeoman Command Line

Here's where things are right now for Yeoman in NetBeans IDE. First, as pointed out yesterday, just like Maven projects from archetypes, you can create HTML5 applications from Yeoman:

When Next is clicked above, all the Yeoman generators that have been installed are shown, exactly as when you run "yo --help" on the command line:

(A feature I'd like to have would be to either have hardcoded or somehow generated the Yeoman generators that are listed here and then to let the user select the ones they'd like to have installed for them via NetBeans.)

(Also need to work more on the responses required from the generators. Right now, Enter is clicked automatically and the default generator is run.)

When Next is clicked above, the name of the selected generator determines the suggested project name of the application that will be generated.

When Finish is clicked, the generator is run in the location specified above, with the result shown below.

The next step is for me to add an 'nbproject' folder in there, with the correct content, so that the application will be recognized as a NetBeans HTML5 application. And then it will automatically be opened into NetBeans IDE, i.e., as soon as it has been generated via the steps above!

Geertjan's Blog - January 22, 2015 04:19 PM
Parsing the Yeoman Command Line

The Yeoman command line, when you run "yo --help", shows you the available Yeoman generators that you have installed:

Integrating Yeoman into NetBeans IDE means that you want to let the user make use of those generators from within a New Project wizard, i.e., as discussed in this blog yesterday. So, here you go, thanks to Steve Souza (sitting on the couch at Concerto in Amsterdam next to me, great coffee and free Wifi hurray) and me:

The code for this is here on GitHub: YeomanHelpParser.java. You'll see the Yo executable is hardcoded, that's one thing I'll be working on, via a new item in the Options window.

Now that the above is done, things are looking pretty good. The user will select one of the installed generators (there'll also be a list of available generators that haven't been installed yet), click Next, and then the "yo" command will be called from NetBeans, the app will be generated, and will open automatically as an HTML5 project (from existing sources) in NetBeans. (JBoss Forge and LazyBones support for NetBeans should be implemented in a similar way.)

Adam Bien - January 22, 2015 12:49 PM
Listing Docker Containers with Nashorn

Nashorn is a convenient REST-service client:


#!/usr/bin/jjs -fv
var host = "DOCKER_HOST"
var dockerUri="http://${host}:5555/containers/json";
var command = "curl ${dockerUri}";
$EXEC(command);
var containers = JSON.parse($OUT);
for each(container in containers){
	print("${container.Image} 	 ${container.Names[0]}	 ${container.Status}");
}

See also: https://github.com/AdamBien/watchdock

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Real World Java EE Workshops [Airport Munich]>

APIDesign - Blogs - January 22, 2015 09:52 AM
Can Real Threads be Brought to JavaScript?

What it would take to bring Java like threads into JavaScript (via Bck2Brwsr VM)? Here is my [[1]]!

--JaroslavTulach 09:52, 22 January 2015 (UTC)

Geertjan's Blog - January 21, 2015 08:57 AM
How to Implement Yeoman in NetBeans IDE

I've been looking into what it would take to support Yeoman in NetBeans IDE. My initial idea was to use the dynamic actions mechanism (see it on YouTube here), to create something like the "External Tools" functionality in IntelliJ IDEA, where you can register Yeoman configurations as external tools, which means each configuration gets a keyboard shortcut, menu item, and toolbar button for invoking the configuration.

I showed the above approach to Ralph Ruijs yesterday and his immediate reaction was along the lines of: "That's just weird. If I want to create a new project via Yeoman, I'd expect to be able to go to the New Project wizard and have access to all the available Yeoman commands via a Yeoman category." Of course, it's a pity I can't use the dynamic actions approach but I agree that it doesn't apply so well in this context. So then I spent some time working on "dynamic project templates" instead of "dynamic actions", which is doable, but even more difficult.

And then... I thought about how Maven archetypes are suppored in NetBeans IDE:

When you want to create a Maven project from an archetype from the on-line Maven repository, you go to the above project template in the New Project wizard. When you click Next above, you see this dialog:

What that means for Yeoman (and for JBoss Forge, I believe) is that, assuming one wants to be consistent with the existing NetBeans IDE approaches, is to create an entry point like this:

When Next is clicked above, a dialog should appear similar to the second step of the Maven archetype wizard. At that point, "yo -- help" should be run (same as is done for grails and griffon in NetBeans IDE), which will then give access to the available generators, which should be made available in a drop-down list, which the user can then select, at which stage the generators are executed.

In other words, that means (1) no dynamic actions are needed and (2) no dynamic project templates are needed. Instead, a much simpler solution based on an existing NetBeans pattern is applicable here and, as you can see above, will provide a very clear entrypoint into Yeoman from within NetBeans IDE.

NetBeans Zone - The social network for developers - January 20, 2015 09:00 PM
Free Virtual Technology Summit with NetBeans Session

The Oracle Technology Network (OTN) is excited to invite you to the Virtual Technology Summit Series.  Four times a year come and join us to learn first hand from Oracle ACEs, Java Champions, and Oracle product experts, as they share their insight and expertise on using Oracle technologies to meet today’s IT challenges. Four main content areas covered will be Database, Java, Middleware and...

Geertjan's Blog - January 20, 2015 08:48 PM
Free: Virtual Technology Summit by Oracle Technology Network

The Oracle Technology Network (OTN) is excited to invite you to the Virtual Technology Summit Series.  Four times a year come and join us to learn first hand from Oracle ACEs, Java Champions, and Oracle product experts, as they share their insight and expertise on using Oracle technologies to meet today’s IT challenges. Four main content areas covered will be Database, Java, Middleware and Systems.  

Are you struggling in being productive with Maven, HTML5 frameworks such as AngularJS, IoT hardware such as the Raspberry Pi, and Java EE? Do you want free, easy to use, out of the box tools for quickly and efficiently developing all kinds of applications? You really need to give NetBeans a whirl!

In the "Free Open Source Tools for Maven, HTML5, IoT, and Java EE" session, during the upcoming free Virtual Technology Summit by OTN (nice and simple URL http://oracle.com/otnvts) we'll show you the latest enhancements and cool features of the free, open-source NetBeans IDE, which are used around the world, from engineers at Boeing and NASA to Java architects such as James Gosling and Stuart Marks!

If you haven't looked at the NetBeans IDE lately, you'll be blown away by the fast speed and performance enhancements. If you are completely new to the NetBeans IDE, see how easy it is to get started and be productive.

Tip: The full agenda is available here and notice that the session described above is in the Java Content Area: https://community.oracle.com/docs/DOC-894285

The sessions are prerecorded, while the speakers and other experts will be available live, to answer questions. To give a sneak peak at what the site will look like, take a look at these two screenshots from the session described above.

Click below to register. Pick a date and time that matches your location:

  • Americas February 11th - 9am to 12:30 PT - click here.
  • EMEA February 25th - 9am to 12:30 GMT - click here.
  • APAC March 4th - 9:30am to 1pm IST - click here.

Spread the news to members of your JUGs, colleagues at your office, and fellow students at your schools, colleges, and universities!

Adam Bien - January 20, 2015 04:35 AM
Amazon AWS Became Lightweight--Support For Java 8 and GlassFish 4.1 Available

Amazon AWS supports GlassFish 4.1 on Java 8. Now you can focus on business logic and push skinny WARs to the cloud.

Big thanks to Robert Herschke for the hint.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - January 19, 2015 08:24 AM
Gulp for NetBeans IDE (Part 2)

Turns out there was no point in getting started making Gulp support for NetBeans IDE myself, since it's already part of daily development builds, and much better than my support was going to be.

For details on this and all the other awesome new features that are already available, go here:

wiki.netbeans.org/NewAndNoteworthyNB81 

Geertjan's Blog - January 18, 2015 08:00 AM
Gulp for NetBeans IDE (Part 1)

The first part of Gulp support is complete. When the plugin is installed, the 'gulpfile.js', if it exists, is parsed and all the Gulp tasks are shown as child nodes of a new Gulp node in the Projects window:

Creating the above was trivial. Initially I got into all kinds of problems when I started by creating a new file type for Gulp files. But the solution ended up being much simpler than that. Using the NetBeans Project Type Extension Tutorial, I registered a new org.netbeans.spi.project.ui.support.NodeFactory for the org-netbeans-modules-web-clientproject project type.

All the code is here:

github.com/GeertjanWielenga/Gulp

The next step I'm working on is being able to run those Gulp tasks from within NetBeans. Once that's done I'll publish the plugin in the NetBeans Plugin Portal.

Adam Bien - January 17, 2015 02:18 PM
Java is #2 at the Tiobe Community Index

According to the TIOBE Community Index Java is #2, C is #1 and JavaScript is #7 and the programming language of 2014.

So if you learned C at school and are using JavaEE at the backend, HTML 5 + JavaScript at the frontend you are one of the cool kids :-)

Subscribe to airhacksnews.com newsletter.


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - January 17, 2015 08:06 AM
Knockout.js in 2 Minutes (Part 3)

Instead of hardcoding the values, let's read them from a JSON file, "courses.json", which I have in the same folder as the "index.html" file:

[
    {
        "name": "John",
        "courses": [{"title":"History"},{"title":"Geography"}]
        
    },
    {
        "name": "Bob",
        "courses": [{"title":"Science"}]
        
    },
    {
        "name": "Susan",
        "courses": [{"title":"Math"},{"title":"English"}]
        
    }
]

Code:

					

Geertjan's Blog - January 16, 2015 03:00 PM
Knockout.js in 2 Minutes (Part 2)

If you liked part 1, you should squeeze in another 2 minutes and watch part 2!

Code:

<script src="js/libs/knockout/knockout-min.js" type="text/javascript"></script>

Name: <input data-bind="value: name, valueUpdate:'afterkeydown'" />

<h3>
    Hello, <span data-bind="text: name"></span>.
</h3>
<ul data-bind="foreach: courses">
    <li><span data-bind="text: title"></span></li>
</ul>

<script type="text/javascript">
    
    var viewModel = {
        name: ko.observable("John"),  
        courses: ko.observableArray([{"title":"History"},{"title":"Geography"}])  
    };
    ko.applyBindings(viewModel);
    
</script>

Geertjan's Blog - January 15, 2015 08:00 AM
Knockout.js in 2 Minutes (Part 1)

Scratching your head over Knockout.js? Spend two minutes getting your feet wet here:

Code:

<script src="js/libs/knockout/knockout-min.js" type="text/javascript"></script>

Name: <input data-bind="value: name, valueUpdate:'afterkeydown'" />

<h3>
    Hello, <span data-bind="text: name"></span>.
</h3>

<script type="text/javascript">
    
    var viewModel = {
        name: ko.observable('John')  
    };
    ko.applyBindings(viewModel);
    
</script>

Adam Bien - January 15, 2015 07:54 AM
10th Airhacks.tv Q & A Uploaded--Killer Servers, Complex JSON, EARs and Modularization

14+ questions answered in 37 minutes:

Subscribe to airhacksnews.com and receive updates about my upcoming "airhacks" events, new workshops, opensource projects and publications.

See airhacks.tv for past episodes.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - January 14, 2015 01:36 PM
NetBeans Day in the Netherlands: 12 February 2015

During NetBeans Day 2014 in San Francisco, mention was made of more NetBeans Days being planned over the coming months. NetBeans Day Germany was held in Munich during December, hosted by Oracle, see the pic below, and read the report here.

In the Netherlands, the equivalent event to the above will be held on 12 February, i.e., less than a month from now, again hosted by Oracle:

Fill in the registration form and join the NetBeans community at the event:

https://pidome.wordpress.com/netbeans-day-februari-12th-2015-the-netherlands/

Or, even better, if you're not available to be there, because you're in some other country, set up a NetBeans Day yourself! Drop me an e-mail (geertjan dot wielenga at oracle dot com) and the NetBeans team will help set up the day, contact an Oracle office if needed for the location and food, and assist in getting speakers for your NetBeans Day!

Adam Bien - January 14, 2015 08:05 AM
JSON-P and JAX-RS 2 Client Maven Dependencies For RESTEasy

RESTEasy is a JAX-RS 2.0 implementation and comes with JAX-RS 2.0 client implementation / provider.

To use RESTEasy as a JAX-RS 2.0 client implementation (e.g. for system testing) you will have to declare the following dependencies in pom.xml:


<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.10.Final</version>
</dependency>
<dependency>
	<groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-json-p-provider</artifactId>
    <version>3.0.10.Final</version>
</dependency>

The choice of the JAX-RS implementation does not have any effect at the code--it remains implementation independent:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

@Test
public void oracle() {
	Client client = ClientBuilder.newClient();
	String content = client.target("http://www.oracle.com/technetwork/java/index.html").
			request().
			get(String.class);
	assertNotNull(content);
	assertTrue(content.contains("java"));
}

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - January 13, 2015 08:00 AM
Free: Learn NetBeans on Udemy

Free! An excellent course for anyone working with NetBeans IDE, covers all the basics, as well as many advanced features. It is unbelievable that a course this good is available for free, make use of the opportunity today!

Click the image above or click here to get directly to the site to get started with the course!

Geertjan's Blog - January 12, 2015 12:28 PM
Free: Learn Java with NetBeans on Android

Free! Start learning Java and NetBeans on your Android phone today. A step by step guide is available that can be installed on Android, with many instructions and a thorough guide to Java with many illustrations and insights into NetBeans IDE:

Go here or click the link above and happy learning!

https://play.google.com/store/apps/details?id=net.samaysoftware.javanetbeans

APIDesign - Blogs - January 12, 2015 09:27 AM
Bck2Brwsr @ 0.13 Released

Bugfix release of Bck2Brwsr 0.13 is out and it powers another classical game: fifteen. Give it a try!

--JaroslavTulach 09:27, 12 January 2015 (UTC)

Michael's blog » NetBeans - January 11, 2015 09:53 PM
Select NetBeans user dir during installation

Some years ago, I suggested to add an option during install to select NetBeans UserDir and CacheDir [1]. This still seems to be an issue for other people. Take a look at the comments on my former blog post [2]. … Continue reading

Adam Bien - January 11, 2015 07:33 AM
Transactions, Scopes, Single Page Apps, Killer Servers, Complex JSON, Modularization Again--Questions For the 10th Airhacks Questions and Answers

Questions for the first 2015 airhacks.tv, but late show at Januar, 12th, 6 PM CET:

  1. Year 2014 Review and Announcements
  2. Introducing project headlands
  3. What are your overall “Java EE” favorites? (peter, via email)
  4. Which technology stack would you prefer to choose for an interactive single page mobile app? As JavaFX is not supported by Apple, I am currently experimenting with a hybrid web app technology stack: GWT, MGWT, PhoneGap. I evaluated Vaadin for this purpose, but integrating custom widgets into their complex architecture seems to be a real pain. Something like Java EE + Primefaces seems not be the first candidate for a single page app to me. What would your approach be? (Jens)
  5. What application server are you currently using for your new Java EE7 projects? Would you recommend GlassFish 4.1 despite the lack of commercial support, or is better to go with WildFly 8.2.0? Antonio
  6. What is your opinion about Project Avatar (https://avatar.java.net/)? WurstFromHell
  7. Portable error reporting with JAX-RS 2.0 Benjamin
  8. How to map complex object strategies to JSON? Remko
  9. I would like to know what would be the best approach for modular JSF applications.

    Most of the existing examples consist in creating a jar, for web applications, where the resources are located in the META-INF folder, having unique named properties files, and using CDI to announce the module existences henry
  10. What about building enterprise systems made of multiple ears, whereas each ear is build as you described? Still, there are many issues not covered yet by appserver providers and JEE.

    (1) One example is that remote ejb proxies are not automatically recovered after deployment - custom proxy factories need to be implemented.

    (3) Another one is the communication between wars … there is actually no kind web client project type available to provide an API for JSF apps - needed to integrate apps at different WARs (for EJB jars we JEE provides client projects…).

    (3) Another aspect … how to develop single EARs with one or more teams/team members? How to hide parts of sources to subcontractors, but ensure deployability?

    From my perspective, development of integrated service landscapes with JEE is still a challenging and not that easy as many hello world example show … that’s why - hope to see more of really real-world enterprise patterns here and also provided by next JEE versions! Andreas Freier
  11. I would like to have something like:

    @Inject @Any private Instance providers;

    Where ‘ServiceRemote’ is a @Remote interface, and there are multiple implementations deployed in different EARs.Chris
  12. I was looking at the Arunja implementation of TransactionSynchronizationRegistry in JBoss and get/putResource works by accessing the resource from the transaction object. You state that this mechanism is independent of TLS, but how does the container get the TSR in the first place, so that it can inject it, if it doesn’t do it using TLS? Ant
  13. Today I saw some code were a @SessionScoped bean was injected into a @Stateless

    EJB.Up-to-now my understanding was that such a constellation will lead to
    unpredictable behavior, since the stateless EJB is not stateless anymore.After googling that topic I figured out that may people stating, such a
    constellation is absolutely valid.I can’t believe that’s true. How is this working?

    Do you have an advice for me? Juergen
  14. Can you please explain how to configure hazelcast as a distributed cache on multiple servers? Eyal

Do you have any additional questions? Ask now, or wait a month :-)

You can ask additional questions live, during the show using the chat: http://www.ustream.tv/channel/adambien, twitter (hashtag "#airhacks") or (the best option): using channel ##airhacks on http://freenode.net.

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.

See you at Java EE Workshops at Munich Airport, Terminal 2 or on demand and in a location very near you: airhacks.io!


Real World Java EE Workshops [Airport Munich]>

DukeScript - January 09, 2015 09:53 AM
A little Game (3)

In the last posts we created our 15-puzzle, took care that it is solvable, made it persistent and added a Function for restarting the game.

For todays post I promised you to make the thing responsive, so it fits nicely on the screen of a mobile phone, but also can be played on the desktop.

But maybe you want to play it:

Here’s the bck2brwsr version of the game

Responsive Web Design

Typically responsive design starts now with the smallest device in mind. With the advent of CSS3 web developers use media queries to define the basic layout for ranges of devices with similar screen size. Inside these ranges the use fluid layout techniques to adjust to the specific device size. Or they use grid frameworks like bootstrap to simplify that.

Responsive Design for DukeScript

In DukeScript we do the same with some specific requirements. On Desktop, iOS and Android the WebView components we are using are pretty capable and modern. That’s good for us so we need no (less) hacks and polyfills. But while web pages are typically scrolled vertically, Apps most of the time should fully fit on the screen. Try for example the great 2048 game on your mobile phone. In portrait mode it works ok. In landscape mode you need to scroll the playing field. For a web page that’s OK, but it’s not what you want from a game. We need to keep that in mind when designing our apps.

Media Queries

The Android/iOS version of the 2048 game solves the problem by locking it to portrait mode. So even if you rotate the iPhone the game won’t rotate. We could do that with some hacks, but actually it’s nicer to allow people to play in both modes.

CSS introduces Media queries that help us discover screen orientation:

@media screen and (orientation: landscape){
    /* some css */
}

@media screen and (orientation: portrait){
    /* some css */
}

New CSS3 units vh and vw

If we want our tiles to fit the screen, we need to size it relative to the smaller side. In landscape mode the small side is height, in portrait mode it’s the width. CSS3 introduces two new size units vh and vw. That stands for Viewport Height and Viewport width respectively. A value of 100vw is the full width, and 50 vh is half the height, you get the idea…

So we can size our tiles so they fit the screen and leave some space around them:

.tile{
    position: absolute;
    vertical-align: middle;
    text-align: center;
    color: #2B1B33;
    -webkit-transition: all 0.5s ease-out;
    border-radius: 5px;    
    background:#93BEA0;
}

@media screen and (orientation: landscape){
    .tile{
        line-height:15vh;
        height: 15vh;
        width: 15vh;   
        font-size: 11vh;
    }
}

@media screen and (orientation: portrait){
    .tile{
        height: 15vw;
        width: 15vw;   
        font-size: 11vw;
        line-height:15vw;
    }
}

We use the new units for height, width and font size. Setting the line-height is needed to vertically center the text. Now we’ve got something like this:

A tile

We can also use the same units for positioning the tiles:

@media screen and (orientation: landscape){
    .tile{
        line-height:15vh;
        height: 15vh;
        width: 15vh;   
        font-size: 11vh;
    }

    .tile.tile-position-1-1 {
        top:1vh; left: 1vh; }
    .tile.tile-position-1-2 {
        top:1vh; left: 17vh; }
    .tile.tile-position-1-3 {
        top:1vh; left: 33vh; }
    .tile.tile-position-1-4 {
        top:1vh; left: 49vh; }
/*...*/
}

@media screen and (orientation: portrait){
    .tile{
        height: 15vw;
        width: 15vw;   
        font-size: 11vw;
        line-height:15vw;
    }
    
    .tile.tile-position-1-1 {
        top:1vw; left: 1vw; }
    .tile.tile-position-1-2 {
        top:1vw; left: 17vw; }
    .tile.tile-position-1-3 {
        top:1vw; left: 33vw; }
    .tile.tile-position-1-4 {
        top:1vw; left: 49vw; }
/*...*/

}

So we have a responsive design now that resizes correctly and fits on any screen. Due to the absolute positioning our grid is in the left upper corner. We can fix that by adding relative positioning to the grids container, give it a size and make centering it. I’m only showing it for landscape now. For portrait it’s the same just with vw instead of vh:

#grid{
    position:relative;
    /* also some styling: */
    background: #375A62;
    border-radius: 5px;
}

@media screen and (orientation: landscape){

    #grid{
        width: 65vh;
        height: 65vh;
        margin: auto;
    }

    /*...*/
}

The value of ‘auto’ for the margin is responsible for centering the grid. We now have a square that’s 65% of the small side in either orientation. So we’ve got some space left above the grid to add some displays showing the number of moves.

<html>
    <head>
        <title>Sort the Tiles</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/styles.css" />
        <link rel="stylesheet" href="css/fontawesome/css/font-awesome.min.css">
    </head>
    <body id="body">

        <div id="game" >
            <div class="fa fa-refresh" id="shuffle-button" data-bind="click: shuffle" ></div>
            <div id="best" >
                <span class="display-title" >BEST</span>
                <span class="display-text" data-bind="text: best"></span>
            </div>
            <div id="moves" >
                <span class="display-title" >MOVES</span>
                <span class="display-text" data-bind="text: moves"></span>
            </div>
            
            <div id="grid" data-bind="foreach: tiles">
                <div class="tile" data-bind="text: p,css: 'tile-position-'+ (y()+1) +'-'+(x()+1), attr: { id: 'tile-'+ p() }, click: $parent.move"></div>
            </div>
            <div data-bind="text: 'Hooray!', visible: solved "></div>
        </div>
    </body>
</html>

You can see that I’ve added fontawesome, which provides nice resizable icons in form of a font. The ‘shuffle-button’ uses that now. With fontawesomes CSS you can simply add classes to an element (class=”fa fa-refresh”) so it displays the icon.

I’ve also added two divs for showing the moves you took to solve the puzzle and the best result so far. In the CSS I place them above the grid like this:

#shuffle-button{
    color: #375A62;
     vertical-align: middle;
    text-align: center;
}

#moves{
    text-align: center; 
    background: #375A62;
    color: #E3E2AF;
    border-radius: 5px;
}

#best{
    text-align: center; 
    background: #375A62;
    color: #E3E2AF;
    border-radius: 5px;
}
@media screen and (orientation: landscape){
    #shuffle-button{
        font-size: 8vh;
        margin-left: 16vh;
        height: 15vh;
        width: 15vh;
        line-height:15vw;
    }
    
    #moves{
        float:right;
        margin-right: 1vh;
        margin-top: auto;
        height: 15vh;
        width: 15vh;
    }

    #best{
        float:right;
        margin-right: 1vh;
        margin-top: auto;
        height: 15vh;
        width: 15vh;

    .display-text{
        color: #E3E2AF; 
        font-size: 8vh;
    }

    .display-title{
        color: #E3E2AF; 
        font-size: 4vh;
    }
    }
/*...*/
}

Sizing is again relative using vh and vw, and I use float to place the items left and right respectively.

That’s it. Like this we’ve got a responsive layout that works on phones in portrait mode:

A tile

And it also works in landscape orientation:

A tile

In an ideal world our team contains a web developer who knows all the CSS tricks and takes care of this, while you, the Java developer writes the business logic. But a lot of time this is among our own responsibilities so it’s good to know at least a little bit about this domain. I recommend getting a nice book on this topic. I’ve got “Responsive Web Design with HTML5 and CSS3” by Ben Frain, which does the job pretty well.

That’s it for this time. Next time we’ll add some sound to the game.

Adam Bien - January 09, 2015 08:33 AM
JCache / JSR-107 RESTification--Project Headlands v0.0.1

Project Headlands is a Java EE 7 / Java 8 WAR which exposes the JCache API via JAX-RS (REST). See sample API scenario. Headlands was tested on WildFly and GlassFish.

Headlands uses hazelcast.org as default JCache SPI. The Reference Implementation could be used as well.

Because out-of-the-box Headlands ships with hazelast, by deploying WARs on multiple servers you get a distributed cache / in-memory grid "for free".

Headlands is already used in production. We will also discuss headlands together with docker as one of the samples at the upcoming Airhacks: Java EE Microservices.


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - January 09, 2015 08:00 AM
YouTube: Dynamic Actions in the NetBeans Platform

Sometimes you'd like your users to be able to create their own Actions at runtime, in addition to the Actions you may have predefined for them. Here's an example of how that would work, i.e., add new Actions and their Presenters to the User Directory, as shown here:

Geertjan's Blog - January 08, 2015 04:28 PM
Classpath for Python Projects in NetBeans IDE

I've mentioned in this blog a few times recently the strides being made in rejuvenating the NetBeans support for Python, most recently in YouTube: Code Completion for Python in NetBeans IDE 8.0.2.

The newest development in that regard is new support for registering libraries on the classpath of Python projects (click to enlarge the image):

The above new feature isn't available in binary form yet, it's still being worked on. For the current state of the NetBeans IDE 8.0.2 plugin for Python, which includes quite some features already, including basic code completion, go here:

http://plugins.netbeans.org/plugin/56795/python4netbeans802

And, if you're lucky enough to be attending NetBeans Day in the Netherlands (12 February 2015), you'll find there'll be a session where the new Python features for NetBeans IDE 8.0.2 will be shown. Sign up for that event here:

http://pidome.wordpress.com/netbeans-day-februari-12th-2015-the-netherlands/

Geertjan's Blog - January 07, 2015 07:54 PM
NetBeans Software for Explosive Ordnance Disposal & Clearance Divers

Operating from offices in Edinburgh, Scotland, and San Diego, California, SeeByte has achieved a position of leadership in the development of smart software for underwater vehicles, sensors and systems in both the Military and Oil & Gas sectors. SeeByte provides products and services to major government and commercial clients around the world and a number of these products are developed using the NetBeans Platform.

SeeTrack Military is the leading technology used by Explosive Ordnance Disposal (EOD) and Clearance Divers around the world, to achieve success in managing their off-board assets during dangerous and demanding missions. As a commercially available, equipment independent mission planning, monitoring and post-mission analysis tool, SeeTrack Military generates a single integrated picture of events from multiple sensors and platforms, providing actionable information and fast results when it matters most. Designed with the operator in mind, this unique system for rapid on-site analysis and fusion of sensor data has been effectively utilized within numerous military & security exercises, surveys and operations.