Wednesday, November 29, 2017

Easy Java EE Microservices with Payara Micro

Wondering how to get started with Java EE Microservices?  It only takes a few quick steps to deploy a Microservice using Java EE APIs.  Many think that Java EE is too heavyweight for use with Microservices, but that is simply not the case...especially if you only utilize the Java EE specifications that are required by your service.  In this brief post, I'll demonstrate how to quickly develop a Microservice with Java EE and then deploy to Payara Micro.

To download the example project, please go to GitHub: https://github.com/juneau001/SimpleService

For the purposes of this example, I will utilize NetBeans, but any Java IDE will suffice.  To get started, create a Maven web application and name it SimpleService.  Next, create two Java packages:  org.simpleservice and org.simpleservice.entity.  Once complete, the project should resemble the following figure:



Now many believe that a Microservice should not connect to an enterprise database, but I will leave that for those who wish to debate.  In this example, I will connect this service to a central Apache derby database to obtain data because I believe this to be a very likely scenario in many organizations.  In this case, we'll create a "Suggested Name" database web service, which will query a database table of suggested names for the upcoming EE4J platform.  To create the infrastructure, connect to a local Apache Derby database and create it using the following SQL:

create table SUGGESTED_NAME (
id numeric primary key,
name varchar(150));

insert into suggested_name values(1, 'Open EE');
insert into suggested_name values(2, 'Open JOE');
insert into suggested_name values(3, 'Cappucino');

Next, open the Maven POM file for the SimpleService project and add the following dependencies:

<dependencies>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>javax.ejb-api</artifactId>
            <version>3.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
            <version>2.5.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.14.1.0</version>
        </dependency>
    </dependencies>

Note that there is no Java EE dependency.  This is because I am utilizing only those dependencies that are required for the service.  Each dependency is added separately.

Next, create a package org.simpleservice.entity, and create an entity class named SuggestedName within it.  For brevity, I'm not going into all of the sources here, but you can check the sources out on GitHub (https://github.com/juneau001/SimpleService).

We'll need to implement our JAX-RS web service class next.  To configure the Java EE application for JAX-RS, let's create a class named ApplicationConfig and place it within the org.simpleservice package:
import java.util.Set;
import javax.ws.rs.core.Application;

/**
 *
 * @author Juneau
 */
@javax.ws.rs.ApplicationPath("rest")
public class ApplicationConfig extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<>();
        resources.add(org.simpleservice.SuggestedNameService.class);
        return resources;
    }
}

Next, I'll create the JAX-RS web service class itself, and I will name it SuggestedNameService.  Here are the sources for the SuggestedNameService class.  Note that I have injected a Persistence Unit.  I will get to that next.


@Stateless
@Path("suggestedNameService")
public class SuggestedNameService {
    @PersistenceContext(unitName = "SimpleService_1.0PU")
    private EntityManager em;
    @GET
    @Path("{id}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public SuggestedName find(@PathParam("id") BigDecimal id) {
        SuggestedName suggestedName = null;
        try {
            suggestedName = (SuggestedName) 
                    em.createQuery("select object(o) from SuggesetedName o " +
                    "where o.id = :id")
                    .setParameter("id", id)
                    .getSingleResult();
        } catch (NoResultException ex){
            System.out.println("Error: "  + ex);
        }
        return suggestedName;
    }
   
    @GET
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<SuggestedName> findAll() {
        List<SuggestedName> suggestedNames = null;
        try {
            suggestedNames = em.createQuery("select object(o) from SuggestedName o")
                    .getResultList();
        } catch (NoResultException ex){
            System.out.println("Error: "  + ex);
        }
        return suggestedNames;
    }
    protected EntityManager getEntityManager() {
        return em;
    }
    
}

Since this service will connect to a database, I will create a persistence unit for the project.  This can be easily done in NetBeans by right-clicking the project and choosing New->Persistence->Persistence Unit.  Name the persistence unit SimpleService_1.0PU and use EclipseLink as the provider.  Do not add a data source at this point.

Once created, open the Persistence Unit and add the connection information.  In this case, I will connect to a JTA data source that I'll define next.  The data source is named DerbyDataSource, so the content of the Persistence Unit (persistence.xml) should look as follows:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="AuthorService_1.0PU" transaction-type="JTA">
    <jta-data-source>java:global/DerbyDataSource</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

Create a web.xml deployment descriptor for the project.  If doing this within NetBeans, simply right-click the project and choose New->Web->"Standard Deployment Descriptor (web.xml) and click Finish.  Once the web.xml deployment descriptor has been generated, add the data source to it.

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
<data-source>
        <name>java:global/DerbyDataSource</name>
        <class-name>org.apache.derby.jdbc.ClientDriver</class-name>
        <server-name>localhost</server-name>
        <port-number>1527</port-number>
        <url>jdbc:derby://localhost:1527/acme</url>
        <user>acmeuser</user>
        <password>yourpassword</password> 
    </data-source>
</web-app>
That's it for the Java EE application.  You should now be able to compile the project into a WAR file and deploy to GlassFish, Payara, or another Java EE application server of your choice.  In this case, let's deploy to Payara Micro. 

To begin, download the latest Payara Micro JAR file from the website: https://www.payara.fish/payara_micro

Once downloaded, the server can be started up by opening a command prompt and executing the JAR with your local Java runtime by typing:

java -jar payara-micro-4.1.2.174.jar

To deploy the application (microservice) that we've created, simply utilize the --deploy option when executing the Payara Micro JAR, and point it to the SimpleService WAR file:

java -jar payara-micro-4.1.2.174.jar --deploy SimpleService-1.0.war

The SimpleService microservice can now be accessed via the following URL:  http://localhost:8080/SimpleService-1.0/rest/suggestedNameService





Saturday, November 04, 2017

Utilizing Apache NetBeans with JDK 9

Did you know that you can build Apache NetBeans from scratch today and utilize the latest JDK 9 features?  Here is how to do it:

Clone the NetBeans Incubator sources to your machine:

git clone https://github.com/apache/incubator-netbeans

Build using JDK 8 and Ant 1.9.9 by traversing into the cloned incubator-netbeans directory and invoking the ant build:

ant

Once the build is complete, traverse into the nbbuild/netbeans directory to see the resulting IDE build.  Run the IDE by invoking the executable or shell script contained within nbbuild/netbeans/bin.





Friday, September 08, 2017

Open EE: My Thoughts on an Open Java EE Platform

About two years ago, thousands of Java developers attended the JavaOne 2015 conference and learned about specifications and features that would be part of the Java EE 8 platform.  These features included the MVC 1.0 specification, Java EE Security 1.0, Microservices, CDI and more.  Java EE 8 was shaping up to be a great follow-up to the excellent Java EE 7 release.

After JavaOne 2015, progress and news around Java EE went silent.  In early January 2016, I received an invite to a Slack group that was created by some members of the Java EE community.  On the Slack channel, there were discussions around the halt of Java EE, and what the community may be able to do in order to keep it moving forward.  I was humbled by the sense of community from the members of the channel and the devotion to the platform was very evident.  Not long after, the Java EE Guardians were formed, focusing on publicizing the stall of Java EE.  The group put forth effort pressuring Oracle to make a statement and continue moving Java EE forward.  Especially in this fast paced space, looming silence regarding the future of any technology can be taxing on those involved.  Others worked on the Java EE specifications as much as possible, making strides forward.

After almost a year of silence, we started to hear music around Java EE again, and at JavaOne 2016 Oracle unveiled the plan to continue moving Java EE 8 forward, albeit a bit differently than originally planned.  The newly envisioned Java EE centered around Microservices and dropped a few of the specifications that no longer fit into the puzzle.  MVC 1.0, JMS 2.1, and Management 2.0 were taken out of the picture, while the newly proposed Health Checking and Configuration APIs were added.  MVC was eventually handed over to the community, which I think was a great move.  The Health Checking and Configuration APIs, which were clearly aimed toward microservices support, were later taken out of the picture for Java EE 8 due to lack of time.  Java EE 8 had more community involvement than any previous Java EE release, and much of this is likely due to the hiatus.  Java EE 8 moves forward, albeit a bit more lean than originally planned, we are moving forward.

Now, nearing the JavaOne 2017 conference, we are on the heels of a Java EE 8 release.  This release includes much of the original core Java EE 8 plan, bringing the Java EE platform in-line with Java SE 8.  It also enhances CDI support throughout the specifications, brings forth Security 1.0, which is long overdue, and JSON-B, closing the JSON to Java conversion gap that was left after JSON-P was released.  Java EE 8 will be a solid release, and I am thankful to all who are involved in making it happen.  I am sorry to say that I will not be at the JavaOne conference this year when it will likely be released, but I know that my colleagues will keep me in-tune with the latest news coming from the conference!  If you are going, make sure you check out the many great Java EE talks that will be presented.

Almost like a professional sports superstar going out on a high note, Oracle recently announced that they are planning to open source Java EE.  I have to applaud Oracle for all of the great work they've done and the support that they've given to Java EE through the years.  I am hopeful that they will remain engaged even after Java EE is open sourced, as they are a very important player in this space.  In my mind, they chose a perfect time to announce the opening of Java EE, as the Java EE 8 release will mark a great milestone making Java EE even more productive and relevant as one of the top application development platforms in the industry.  The community around Java EE seems as though it has never been more engaged than it is now.  Over the years since the cumbersome J2EE morphed into the productive platform that we call Java EE today, the community has continued to grow by the thousands.  The Java EE Guardians have thousands of supporters, each of them hoping to help move Java EE forward for years to come.

I see a great future for an open Java EE.  However, many questions are left to be answered.  Will the JCP still be used to manage the changes that are proposed for the platform?  Perhaps this is one of the questions that has the potential to impact the platform the most.  If the JCP will still be used to manage the platform, can it be changed in such a way that it will be conducive to a faster moving platform?  Do we want Java EE to become a faster moving platform, much to the likes of other frameworks such as Spring?

One of the main strongholds of Java EE is standardization.  If the open Java EE were to become more dynamic, can it maintain its place as a standard in the industry?  I think so.  I think that ideally the JCP could still be used to move the specifications forward, with a bit of a modernizing on the approach.  I like the idea of having shorter Java EE release cycles with fewer changes in each release.  Such an approach can really help the platform to retain its relevancy in this fast moving space.

What are your thoughts on the opening of Java EE?  I welcome it and look forward to seeing what is to come for JavaOne 2018.

Wednesday, July 26, 2017

Java EE 8: Start Testing Today

Java EE 8 will be finalized and ready for public use soon.  There is no better time to get started testing the new features than now.  You can do so by grabbing a copy of my Java EE 8 Playground project and deploying to GlassFish 5.

I've just updated the project to repair bugs and include better formatted table data within the tables.  I've also added a couple of examples:

- JSON-B example: Allows one to fetch the JSON for customer objects.

- CDI 2.0 Async:  Add a new Job object to see async event output in server log

GitHub Project:  https://github.com/juneau001/JavaEE8-Playground

Saturday, June 10, 2017

Java 9 Recipes Published!

A bit ahead of schedule, my latest book entitled Java 9 Recipes: A Problem-Solution Approach, has just been published!


This book is the 3rd Edition in the Java Recipes series.  It covers all of the information that was in the previous editions, including the new content for Java 9.  Specifically, you will learn how to use new Java 9 features including:


  • Modularity
  • Private Method Implementations in Interfaces
  • Process API Enhancements
  • New Streams API Enhancements
  • HTTP/2 Client API

I'd like to thank Apress for providing me with the opportunity to help share my knowledge of the Java platform.

For more information on using Java 9, check out the tutorials found in this post: https://www.javacodegeeks.com/java-9-tutorials

Wednesday, March 29, 2017

Testing the Java EE 8 Specifications

The Java EE 8 Platform has definitely been moving along within the past couple of months.  Specifications have been releasing early draft reviews, milestones, and even final releases.  As a matter of fact, JSR-372 has just gone final, as JSF 2.3 has been released.  For more information, please see Arjan's Post.  It had the privilege to be a part of the JSR-372 expert group, and I really appreciate the opportunity to work with these experts on a specification that I use every day.

I created a Github Project entitled the Java EE 8 Playground, and it includes a Java EE application that contains a number of the latest updates to those specifications that will be part of the Java EE 8 release.  I will make an effort to update this project often so that it includes current dependencies for the specifications.  I will also try to add demos for the specifications so that it will be easy to build upon the examples.  In the current project, some of the JSF 2.3 features are used.

It is important that as a community we test and provide feedback for the Java EE 8 specifications as they are being developed.  It is in these stages that you have a voice that can make a change to an upcoming specification.  Please test, read the latest specification documents, and provide feedback to the respective JSRs.

Java EE 8 Playground Project:  https://github.com/juneau001/JavaEE8-Playground

Java EE 8 JSRs:

JSR 365 (CDI 2.0):  https://www.jcp.org/en/jsr/detail?id=365
JSR 366 (Java EE 8):  https://www.jcp.org/en/jsr/detail?id=366
JSR 367 (JSON Binding):  https://www.jcp.org/en/jsr/detail?id=367
JSR 369 (Servlet 4.0):  https://www.jcp.org/en/jsr/detail?id=369
JSR 370 (JAX-RS 2.1):  https://www.jcp.org/en/jsr/detail?id=370
JSR 372 (JSF 2.3 - FINAL):  https://www.jcp.org/en/jsr/detail?id=372
JSR 374 (JSON  Processing 1.1):  https://www.jcp.org/en/jsr/detail?id=374
JSR 375 (Java EE Security 1.0):  https://www.jcp.org/en/jsr/detail?id=375
JSR 380 (Bean Validation 2.0):  https://www.jcp.org/en/jsr/detail?id=380

JSR 371 (MVC - No longer officially part of Java EE 8):  https://www.jcp.org/en/jsr/detail?id=371




Saturday, March 04, 2017

JSR 365 Update: Digging Into CDI 2.0

Contexts and Dependency Injection 2.0 (JSR 365), is an update to CDI 1.2, which is currently part of the Java EE 7 platform.  It is currently in Public Review stage.  For those of you who are not very familiar with CDI, it defines a powerful set of complimentary services that act as a gel that help to improve the coordination and structure of application code.  For more details, please visit the specification page.

CDI 2.0 expands the usability of the Contexts and Dependency Injection services to Java SE as well, as it will now target both the Java SE and Java EE platforms.  The CDI specification has been organized into 3 parts, Part I - Core CDI, Part II - CDI in Java SE, and Part III - CDI in Java EE.  The major changes for CDI 2.0 are as follows:

  • Better alignment with Java SE 8
  • API for booting CDI within a Java SE application
  • Ability to provide observer ordering
  • Ability to fire asynchronous events
  • New Configurators Interfaces for Service Provider Interface (SPI) elements
  • Ability to configure or veto an observer method in ProcessObserverEvent event
  • Support for inline instantiation of specific annotation types
  • Addition of the InterceptionFactory interface,  which allows to create a wrapper instance whose method invocations are intercepted by method interceptors and forwarded to a provided instance.
I encourage you to take a look at the CDI 2.0 Public Review Draft for more details on the specifics of each enhancement listed, as well as a complete listing of new features.  Read through the draft and provide feedback to the expert group.  All of the pertinent details for providing feedback can be found on the JSR 365 page.  To get started testing, create a new maven based Java EE application in your favorite IDE, and add the following dependencies:

<dependency>
    <groupid>javax.enterprise</groupid>
    <artifactid>cdi-api</artifactid>
    <version>2.0-PFD</version>
</dependency>
<dependency>
    <groupid>org.jboss.weld</groupid>
    <artifactid>weld-core-bom</artifactid>
    <version>3.0.0.Alpha14</version>
    <type>pom</type>
</dependency>

In this post, we will dig into one of the new features to get you started working with the API.  Let's take a look at asynchronous events.  Until CDI 2.0,  events could only be fired in a synchronous manner.  They've been enhanced in this latest iteration for asynchronous processing.  Here's how it works:

Create an event of some type.  Next, fire the event in an asynchronous manner, and handle accordingly once the event is complete.  In this example, I have created a MovieEvent class, which will be utilized whenever a persist event occurs for a Movie object.  The MovieEvent class is as follows:

public class MovieEvent {
    
    private String message;
    private Movie movie;
    
    public MovieEvent(String message, Movie movie){
        this.message = message;
        this.movie = movie;
    }
    
    public String getMessage(){
        return this.message;
    }
    
    public void setMessage(String message){
        this.message = message;
    }
    
    public Movie getMovie(){
        return this.movie;
    }
    
    public void setMovie(Movie movie){
        this.movie = movie;
    }
    
}

In the following scenario, we are firing an event when a new Movie is persisted.  The following code resides within a MovieController CDI bean of an example JSF application:

@Named("movieController")
@SessionScoped
public class MovieController implements Serializable {

    @EJB
    private com.mycompany.cditest.session.MovieFacade ejbFacade;
    private List items = null;
    private Movie selected;
    
    @Inject
    Event<MovieEvent> movieEvents;
. . .
   private void persist(PersistAction persistAction, String successMessage) {
        if (selected != null) {
            setEmbeddableKeys();
            try {
                if (persistAction != PersistAction.DELETE) {
                    getFacade().edit(selected);
                    movieEvents.fireAsync(new MovieEvent("New Movie Released", selected))
                            .whenComplete((event, throwable) -> {
                                if(throwable != null){
                                    System.out.println("Error has occurred: " + throwable.getMessage());
                                } else {
                                    System.out.println("Successful Movie Processing...");
                                }
                            });
                } else {
                    getFacade().remove(selected);
                }
                JsfUtil.addSuccessMessage(successMessage);
            } catch (Exception ex) {
                Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
                JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            }
        }
. . .

When the event is fired, it creates a new MovieEvent object, and if it successfully completes then a message is printed to indicate success.  In this example, a stream is used to process the "whenComplete" action.

Feel free to clone the repository located at https://github.com/juneau001/CdiTest and take CDI 2.0 test for a spin.  This example is just one simple test of CDI 2.0.  You can clone and utilize this test project as a starting point to work with other aspects of the specification.  Keep an eye on JSR 365, which is currently in the Public Review Ballot stages.


Wednesday, September 28, 2016

JavaOne 2016 Follow-Up

I had the pleasure of attending JavaOne this year, and I can sum up the experience in one word:  Brilliant.  This year was much different than in years past for me, as I had one talk to co-present on Sunday and I had the rest of the week wide open for attending sessions.  As such, I've learned that it really is nice to have a lighter schedule at JavaOne so that you can take in all of the expertise and networking...that is what JavaOne is all about...learning from the experts and growing your network.  I also had my lovely wife along with for part of this trip, which made my stay in San Francisco very nice, as I finally took a few minutes to enjoy the city this year...never had done that in the past.

My conference experience started off with the excellent NetBeans party on Saturday evening.  I am a member of the NetBeans Dream Team, so many of my colleagues were in attendance at this party.  It was the first time I had seen many old friends, and it was great to have a chance to catch up without needing to worry about rushing to the next session.  I want to thank Geertjan Wielenga and Oracle for hosting this excellent event, and I cannot wait until the next Apache NetBeans party.

On Sunday at NetBeans Day, I had the pleasure of presenting "Enterprise Modeling of MVC and Java EE Artifacts" with experts Ivar Grimstad and Gaurav Gupta.  Ivar is on the expert group for JSR 371 (MVC 1.0)...which we hope to move forward for use with Java EE 8.  Gaurav is the lead developer for the excellent JPA Modeler tool.  During our session, Ivar gave an overview of MVC 1.0, Gaurav highlighted the JPA Modeler utility, and I demonstrated how the JPA Modeler could be utilized with JSF applications, as well as MVC 1.0.  I want to thank Geertjan again for getting the three of us together for this excellent talk.

The opening keynote was amazing.  A large portion was devoted to showing how the world is using Java, including the outstanding Mars rover presentation by Dr. Anita Sengupta (@Doctor_Astro).  It was amazing to see the complexity and detail that went into ensuring the Curiosity rover landed without issues.  Of course, Java 9 was mentioned, along with a demo of modularity and the jshell by Mark Reinhold...very informative, as always.

During the opening keynote, I anxiously awaited word on the status of Java EE, and after quite a long wait, the announcement was made.  I am very excited that Java EE 8 efforts are moving forward, albeit a bit differently than previously planned.  Essentially most of the specifications for Java EE 8 is moving forward, and it is proposed that the following be removed so that resources can spend time in other areas: JSR 371 (MVC 1.0) and JSR 368 (JMS 2.1), JSR 373 (Management 2.0).  I will cover my thoughts on these proposed dropped specifications in a follow-up post.  The main focus for Java EE 8 will be to start paving the path for a more micoservices focused platform, whereby Java EE 9 will be released a year later and it will include the full microservices implementation.  The addition of Health Checking and Configuration specifications would be beneficial for providing a standard means by which to monitor services and dynamically configure our applications.  Overall, it is great to see things moving forward for Java EE, although I do have some reservations on the overall approach.  I do not believe that every industry will adopt the microservices architecture, so there needs to be a path for those who will be continuing with the standard Java EE application architecture.

Rather than going through detail on each of the sessions that I had attended, I will provide a summary of my thoughts on the conference overall.  As I have said many times before, time is not our friend...and this certainly was the case this year at JavaOne, as there were too many great tutorials, sessions, and networking events that it was difficult to see everything.  Hats off to Sharat Chander and others at Oracle for organizing such a great conference.  I also want to thank the content review committees for reviewing and choosing such great conference tutorials and sessions...the content was excellent!

The tutorials and hands-on labs dealing with Microservices were hot this year.  I attended two of them myself.  One of them was a hands on lab that enabled us to develop Microservices using JBoss Forge and WildFly Swarm.  It was a fast pace tutorial covering everything from setting up Eclipse (unfortunately not my favorite IDE), through utilizing Forge, constructing services, and deployment.  I am glad I attended, as it gave me a different perspective on development from what I am used to.  The second was a tutorial on utilizing Payara Micro and the Payara MicroProfile.  I found this tutorial very in-depth, covering these technologies from the ground-up, with lots of detailed explanation.  I learned it is quite easy to add the Payara Microprofile to a project, simply by including the dependency in the POM:

<dependency>
   <groupId>fish.payara.extras</groupId>
   <artifactId>payara-microprofile</artifactId>
   <version>1.0</version>
   <scope>provided</scope>
</dependency>

Deploying is as simple as:

java -jar payara-microprofile-1.0.jar --deploy test-app.war 

I attended many key Java EE sessions, including those given by Linda DeMichiel and others leading the specifications.  All of these were informative, covering content from previous Java EE incarnations through what to expect in Java EE 8.  Linda's presentation on Monday went into a bit more detail on the plans for Java EE 8, and it is clear to see that Oracle is "all in" on moving forward with the newly proposed plan for Java EE 8...which is great!  Each of the specification-specific talks that I attended were excellent, including CDI 2.0,  JAX-RS 2.1, and JSF 2.3.  Great to hear from the experts for these areas.  I also took in a couple of other key talks:  Java EE Extendable to Functional by David Blevins, and 50 Java EE Best Practices by Ryan Cuprak and Michael Remijan...both great!

There were a lot of sessions on Java 9 and modularity this year.  I attended a session on modularity, which was a great introduction for those hadn't yet had a chance to experiment with it.  Docker was another hot topic at the conference, and I had the opportunity to attend a couple of sessions covering this great tech.

I had the privilege to attend the JCP Party on Monday evening.  Always an excellent opportunity to network with others in the JCP, and this year's event did not let us down.  The Chicago Java Users Group (CJUG), Bob Paulin, and myself won an award at the JCP Party on Monday evening for Adopt-a-JSR participants of the year.  This was a very nice surprise!  I also attended PartyOne, hosted by Tomitribe, ZeroTurnaround, BainCapital, and Hazelcast.  This was a great opportunity to network with so many experts...and there was also a great view of the Bay Bridge off the balcony.  I want to thank Tomitribe for the invitation!  Lastly, I attended the Oracle Appreciation Event, which was very nice.  The Oracle OpenWorld and JavaOne attendees had AT&T Park to themselves, and we got to see Sting and Gwen Stefani.  Great networking opportunity with many great friends.

Overall, JavaOne 2016 was another great conference...very glad to have been a part of it.  If you have not done so already, please take the Java EE Survey and provide your thoughts on the upcoming Java EE 8 proposal:

http://glassfish.org/survey

Thursday, September 15, 2016

NetBeans Java EE 8 MVC Plugin Enhancements

A while back, Geertjan Wielenga had posted about a NetBeans plugin that had been developed for the upcoming Java EE 8 MVC framework.  The plugin was originally developed by Manfred Riem, co-spec lead for JSR 371, and Geertjan had extended it to add functionality for viewing all of the MVC controllers within an application.  This plugin is a great start to a useful MVC plugin for NetBeans.

I've since taken the plugin and extended it further, adding the following enhancements:

  • NetBeans workspace now scanned to apply plugin only to those projects that contain MVC controller classes.
  • Ability to create a new MVC application which includes a basic controller class and corresponding view.
  • Ability to add new MVC controller class to a project.

Come and check out the new plugin functionality at JavaOne.  I have the honor of presenting along with Ivar Grimstad (JSR 371 Expert Group) and Gaurav Gupta (JPA Modeler) in the presentation UGF6435 -- Enterprise Modeling of MVC and Java EE Artifacts for NetBeans Day 2016.  I'll demo the plugin during the session, alongside the powerful JPA Modeler utility.  

Hope to see you there!

For more information on NetBeans IDE, please check out the Java NetBeans IDE Tutorial.

Friday, July 15, 2016

NetBeans 8.2 Profiler: Colored Results

One of the new features in NetBeans 8.2 is the ability to color profiler results differently based upon filters.  This can make things visually stand out, and easier to follow in the profiler output.

To enable colored profiler results, go into the NetBeans "Preferences"->"Java"->"Profiler" menu, as seen in Figure 1.  Check the box to "Use defined filters for coloring results".

Figure 1:  NetBeans Profiler Colored Filter Results

Add any filter(s) you wish, and assign a color to the results of those filters (Figure 2).  If you wish to display the output from one of the existing filters in a different color, click the tool icon and change the colors.  As you can see in the previous figure, I updated the Java EE Frameworks filter to be a green color.

Figure 2:  Assign Colors to Filters

After applying the colors to the filters, run the profiler and see the results!

Figure 3:  Colored Results!



Saturday, June 11, 2016

Help Move Java EE Forward

If you recall my post entitled Java EE 8:  What is the Current Status, it is apparent that the progression on Java EE has certainly slowed down over the past several months.  There are definitely some JSRs under the Java EE umbrella that have more activity than others, but Java EE as a whole has seen little to no movement forward since JavaOne 2015.  This is not something to be taken lightly by anyone in the IT industry.  Java EE is a critical part of the industry, as there are thousands of web applications that have been built using the Java EE stack.  There are probably even more applications that have not been built using the full Java EE stack, but still rely upon some of the Java EE technologies..such as the Java Persistence API (JPA) or Java Message Service (JMS).

Why is it so important to move things forward?  Why not just leave things how they are and let Java EE fade away?  Plainly put, these technologies need to move forward in order to remain secure and make use of the current API technologies of today.  If one wishes to simply let Java EE stagnate, that means that all of the applications and services utilizing all or part of Java EE (much of the internet as we know it) are also stagnating, and cannot be moved forward to stay current with today's technology and security concerns.

What can we do to try and help?  Move Java EE forward via the community.  If you have a few moments to spare, help move Java EE forward by sharing your expertise and contributing to one or more of the Java EE JSRs.  This can be done by joining the JCP (Java Community Process) and beginning to work on the code.  Work can be categorized in a number of ways...one can test existing code, document, debug, repair issues, or even develop features and enhancements for a Java EE 8 JSR.  Become a part of your local JUG and give a talk on Java EE 8, or get your JUG involved via the Adopt-a-JSR program and work with the JCP to help make improvements towards the Java EE 8 effort!

What can you do right now?  Sign the petition that has been proposed by the Java EE Guardians group to try and persuade Oracle to begin working on Java EE 8, once again.  The Java EE Guardians are a group of individuals/JUGs that are actively involved in trying to vocalize the current status of Java EE 8, in an effort to get the community involved and to make Oracle hear or opinion.  In the end, if Oracle is not interested putting forth effort internally and moving Java EE forward, hopefully they will be open to working more with the community, and hand off some of the specifications to those who are interested.

https://www.change.org/p/larry-ellison-tell-oracle-to-move-forward-java-ee-as-a-critical-part-of-the-global-it-industry

Thanks for reading the post...your time and participation is certainly appreciated!

Tuesday, May 31, 2016

NetBeans Java EE Tip #9: Create JSF Application from Database

Do you need to create an database front-end very quickly?  The NetBeans IDE allows one to develop a JSF application front end for a set of database tables very quickly, and with very little coding.  Now this tutorial is an oldie, but a goodie...and it is worth mentioning again for those who are not aware of it.

First, create your application.  In this case, I create a Maven Web Application by choosing "New Project"->"Maven"->"Web Application" (Figure 1).

Figure 1:  Maven Web Application

Next, I provide the web application name of JsfCustomers since I'll be making use of the CUSTOMERS sample database tables.  Once the application project is created, create a new Java package to hold the entity classes for the database.  In this case, I right-click on the project's "Source Packages" and select "New"->"Java Package...", and then name it org.jsf.jsfcustomers.entity  (Figure 2).

Figure 2:  New Java Package


After the package is created, right-click on it and select "New"->"Entity Classes from Database", which I've covered in a previous posting.  This wizard allows me to select a set of database tables from one of my connections...here I choose my sample database and select the CUSTOMER table.  After doing so, all related database tables are automatically added to the "Selected Tables" list...click next (Figure 3).
Figure 3:  Create Entity Classes from Database


The next wizard page (Figure 4) allows me to select various options for generating my entity classes...I'll leave the defaults and click "Finish".
Figure 4:  Entity Class Options

After doing so, the entity classes for my database have been generated.  Now it is time to put the icing on the cake.  Since the database entity classes are now available, I can generate the entire JavaServer Faces infrastructure with just a few clicks.  Right click on the project's "Web Pages" folder and select "New"->"JavaServer Pages"->"JSF Pages from Entity Classes" (Figure 5).

Figure 5:  Create JSF Pages from Entity Classes

Next, select all of the entity classes that have been created, and click "Next" (Figure 6).

Figure 6:  Select Entity Classes

Lastly, specify options for creating your JSF classes and pages.  First, I specify a good name for my EJB session bean and JSF Controller packages.  The EJBs and controllers will be automatically generated into these locations.  Next, select the web folder where the JSF pages should be generated...leave blank for the root.  Lastly, I chose to utilize the PrimeFaces pages template to make use of PrimeFaces components.  Click next and choose the JSF configuration that has been previously registered with the IDE (Figure 7).  Lastly...click "Finish" and see the magic...the web application and all of the JavaServer Faces infrastructure is generated automatically (Figure 8).

Figure 7:  JavaServer Faces Configuration


Figure 8:  Completed JSF Application

Note that you may need to right-click on your project "Dependencies" module and add PrimeFaces (Figure 9).

Figure 9:  Add Maven Dependency

Now build and run your application...and it is ready to use!












Thursday, May 12, 2016

Working with Mojarra Maven Builds

Some great updates have been made to the Mojarra repository in the past couple of months.  The JSF 2.3 Milestone 5 release has been available to download since March, and the Milestone 6 release is actively in progress.  Arjan Tijms and Bauke Scholtz have been actively contributing to the effort and moving things forward, which is helping Mojarra to maintain a healthy milestone cycle.

One of the biggest efforts that have been made was to complete the transition to Maven builds, rather than ANT.  The ANT build had become rather difficult to maintain over the years, and rather than going through the effort to repair it, the process has been changed over to a Maven build.  Manfred Riem, co-spec lead for JSF 2.3, had originally started this conversion to Maven and had nearly completed the effort, but never made it 100% of the way.  Arjan stepped in and finished the task so that it works with the latest milestones.

To begin working with the actively progressing 2.3 Milestone 6 along with the new Maven build, do the following:

Create a new clone of the Mojarra GitHub repository, or update an existing local repository from remote.

git clone https://github.com/jsf-spec/mojarra.git


Once the clone is complete, execute the following commands within the terminal.  As you can see, you first move into the jsf-tools directory and build/install the artifacts using the mvn clean install command.  Next, move into the impl directory and issue the same command.

cd mojarra

cd jsf-tools

mvn clean install

cd ..

cd impl

mvn clean install

Doing so will create a Milestone SNAPSHOT JAR file in the <repository>/impl/target directory.  You can then start to test against the latest Mojarra sources and check out the newest features.


NetBeans Java EE Tip #8: Persistence Units

The foundational goals of any good IDE are to simply and organize one's code and development workflow.  NetBeans does a superb job of achieving these goals, and sometimes we take the basics for granted.  For instance, if your eyes have ever glossed over from trying to read XML in a plain text editor, you may have had issues configuring and working with Persistence Units in the past.  In case you aren't familiar with Persistence Units, they are XML configuration files that are used by a Java EE project to configure database connections and options.  NetBeans has a very easy-to-use persistence unit wizard, which will be showcased in this post.

For starters, NetBeans provides a wizard for generating a Persistence Unit for a project.  Simply right-click on a project, choose "New" from the context menu, and then choose the "Persistence"->"Persistence Unit" option.

Next, supply a name for your Persistence Unit, along with a Persistence Provider using the drop-down menu of selections.  You can then choose from an available Data Source, and choose a table generation strategy.

Once created, the Persistence Unit can be found within the "Configuration Files" folder of a NetBeans project.

Selecting and double-clicking the file will open the Persistence Unit editor.  NetBeans provides an easy to modify configuration screen for the Persistence Unit that allows changes to be made without working directly with XML.


For instance, one may wish to add an entity class for use with the Persistence Unit.  To do so, simply click the "Add Class" button and choose the desired class(es).


If you'd rather work directly with the XML of a Persistence Unit, choose the "Source" button at the top of the editor.  Rather than seeing drab XML, you will be presented with color-coded and an auto-completing XML document.



Working with history is a breeze with the Persistence Unit configuration within NetBeans.  Choose the "History" button at the top of the editor to see a listing of all changes made to the unit, and it also provides diffs so you can easily see the changes that have been made, and/or apply or revert code, as needed.



NetBeans provides and easy way to work with Persistence Units.  Forget about dealing with XML within a text editor...you'll never want to do that again.

Tuesday, May 03, 2016

NetBeans SQL Profiler - Take it for a Spin!

The upcoming release of NetBeans, currently in active development and testing, boasts plenty of new features.  A few of them include EMCAScript 6 Support, Docker Support, JavaShell Support, and SQL Profiling.  In the latest nightly builds, the SQL Profiler is now available for use, so I took it for a test spin.  In this post, I'll run through just a few of the options available with the upcoming NetBeans SQL Profiler...I think you will be quite pleased.

The SQL Profiler allows one to instantly see which queries are causing the most contention within an application, and enables easy comparison via total running time and invocations against each of the queries that have been executed.  The tool also allows one to perform heap dump, garbage collection in the profiled process, and many other useful features.

To get started with the SQL Profiler, download the latest nightly build of NetBeans, which can be done at the following URL:

http://bits.netbeans.org/download/trunk/nightly/latest/

Next, install and run the IDE, then import or select a project that utilizes a database.  Just like the other NetBeans profilers, a JVM must be calibrated for profiling before the SQL Profiler can be ran against a project that utilizes that JVM.  To perform calibration, select the project and then choose "Profile Project" from the "Profile" menu.  After a JVM has been calibrated, any project using that JVM can be profiled.  Simply select the project, and start the profiler of your choice by selecting the profiler option within the drop-down list.  In this case, I'll choose the SQL Queries option.

Figure 1:  Configuration Page



Figure 2:  NetBeans Profiler Selection Menu

Once the profiler has been started, the application will launch and the most current SQL queries will be displayed in a chart.  In this case, I am profiling a Maven based Web application project running Java EE 7 and JPA.  When the profiler is started, the web application launches and the SQL Profiler screen is displayed.

Figure 3:  NetBeans SQL Profiler Screen

The NetBeans SQL Profiler makes it easy to see which queries have been invoked, how many times they have been initiated, and how long they took to run.  As I run my cursor over the SQL queries, the query that is under my cursor is highlighted, and I am able to click on it to expand the row and see the method invocation stack.

Figure 4:  NetBeans SQL Profiler Method Invocation Stack for Selected SQL

If I choose, I can right-click on a given query, and view the SQL.

Figure 5:  Right Click on a SQL Row

Figure 6:  View SQL Query

As mentioned at the top of the post, I have the ability to perform a heap or thread dump for a selected query, and I can even perform a garbage collection.



The NetBeans SQL Profiler is going to be a great tool for anyone that develops applications utilizing a database backend.  Not only will it allow one to clearly see which SQL is causing the most contention within an application, but it also allows for easy comparison and provides detailed information on the underlying SQL invocations.

Download the latest build to try it out now...otherwise, it will be available with the public release of NetBeans 8.2.  The bonus is that if you try it now and find issues or have comments, you can help the developers make the Profiler even better.

Friday, April 29, 2016

Java EE 8, What is the Current Status: Case Study for Completed Work Since Late 2015

For anyone who pays close attention to Java EE, it has become clear in the past six months that there has been a decline of activity...especially in those JSRs for which Oracle maintains the lead.  What's the deal?  There has been a lot of conversation in the Java EE community in this regard lately, and I think it is important that the developer community be given a fair timeline of what we can expect for the future of Java EE.  The uncertainty is becoming long in the tooth, and the community is becoming more concerned with the future of Java SE and Java EE as time goes on.

Let me give you a bit of background.  I'm an expert group member on a couple of JSRs targeted for Java EE 8, those being JSR 372 (JavaServer Faces 2.3), and JSR 378 (Portlet 3.0 Bridge for JavaServer Faces 2.2).  At the beginning of 2016, I had noticed that since October 2015 the number of emails on the Expert Group list for JSR 372 had really slowed down.   In fact, in the final quarter of 2015, the activity on JSR 372 had slowed down to a near halt, whereas it should be picking up momentum as time moves forward closer to the eventual final release.  In late January, I was contacted by a couple of members of the Java EE community, indicating that they also had seen a slowdown of activity and were very concerned.  I was then asked to join a community of concerned Java EE advocates on a Slack community...and when I joined and read the backlog of messages I could clearly see that it looked as though Oracle had stopped activity in just about every area of Java EE, specifically work on all of the JSRs that were Oracle-led.

I began to do some homework and started looking into the statistics a bit.  I wanted to see some clear evidence.  What I found is that in some JSRs, it was difficult to see a decline in activity on Oracle's part, but these JSRs, in particular, did not have a specification lead that was from Oracle.  Some JSRs, especially those not under Oracle's purview, are just overall more active than others.  On the converse, for those JSRs where Oracle does maintain the specification lead, the activity had almost come to a complete halt.  I'd like to share my findings for a couple JSRs, those being JSR 372: JavaServer Faces 2.3, and JSR 368: Java Message Service 2.1.

I gleaned the following information from the JSR 372 and JSR 368 public archives/records, including the JIRA (Mojarra JIRA and JMS JIRA), mailing list archives (JSR 372 EG Mailing List, JSR 378 EG Mailing List), and the GitHub repository (https://github.com/javaserverfaces/mojarra).

JSR 372 Statistics

First and foremost, I want to mention that the specification leads for JSR 372 are top notch, and they've done a spectacular job of leading the project.  That said, it seems that their activity has dropped off quite a bit since October 2015.  Here are some charts to display the data.

As I had mentioned previously, the JSR 372 specification leads have done a great job.  As such, they've still maintained a role in the email to the JSR 372 expert group mailing list.  That said, these numbers only reflect those through 03/2016...and there has not been much activity since.

If we take a look at the number of commits towards JSR 372 (captured from GitHub), we can see the there is a major decline in the work that has been done from Oracle.  Most of the work that has been done since October 2015 is from the community, mainly the most active JSF developers:  Arjan Tijms and Bauke Scholtz.

Another significant area of decline is in the number of issue resolutions from Oracle.  The following data was gleaned from Github, and the work from Oracle on JSR 372 since March 2016 is much the same.


The graphs above clearly indicate a decline in Oracle's involvement towards the eventual completion of JSR 372.  This is troubling because the work for JSR 372, as well as others encompassed in Java EE 8, is targeted for public release in less than a year (March 2017), and it seems as though that target is becoming more of a wishful goal now than an actual release date for Java EE 8.

JSR 368 Statistics

The statistics for JSR 368 show even more of a decline in activity from Oracle specification lead perspective.  Again, the spec lead has done a superb job leading the project until the changes seem to have been made in late October from the Oracle standpoint.

First, looking at the email, it is plain to see that there has been a drop off.  However, it seems that JMS 2.1 email has been slow for much of 2015.

 The number of commits for JMS 2.1 tell a different story, it looks as though there haven't been any commits done since late 2015.




As far as issue resolutions go, there has been little activity at all for the JMS 2.1 lifecycle.


That is all well and good, but comparing this data against the JMS 2.0 data is where there is a very clear indication that there is not as much effort going into the development of JMS for the 2.1 release.

The main purpose of this post is to alert the Java SE and Java EE communities that there has been a clear decline in the Oracle involvement towards Java EE 8.  I, like much of the rest of the community, am very concerned that the effort going into the Java EE 8 JSRs has declined at an alarming rate, seeming to indicate that this release is not ranking very high on the priority list.

That said, with the exception of the past year's activities, I think Oracle has done a fantastic job in the previous five or six years activating the Java SE and Java EE communities.  I have been proud to wear my GlassFish beanie and Oracle Java EE 7 t-shirts...letting everyone know how great it is to be a part of this community.  I enjoy speaking at conferences about the latest Java EE technologies, and writing posts to share the knowledge.

I think the rest of the community stands with me in saying that it would be good to have a clear statement from Oracle with regards to their intentions for the future of Java EE.  Not only would it help to clear the uncertainty that looms in the air, but it would also help the many customers and organizations that rely upon Java EE to have a clear understanding of what is to come.

I hope that we see activity pick up soon so that we can continue leading the way towards another significant Java EE release in the near future, maintaining the platform's edge when it comes to cutting edge technology.  Looking forward to hopefully seeing the Java SE and Java EE platforms continue to evolve long into the future!

Thursday, April 07, 2016

NetBeans Java EE Tip #7: Overlooked Java Class and XHTML Editor Shortcuts


Sometimes the most helpful features of an IDE are the most overlooked.  In this post, I will outline five NetBeans Java and XHTML editor shortcuts that can be used when developing Java EE applications.

#1 - Easily Fix Namespaces and Classes

Perhaps you have added a new JSF tag to a view for which the namespace has not yet been declared, or maybe you removed a tag that is no longer required, and the namespace is no longer needed.  NetBeans provides the SHIFT+CMD+I (OS X) and CTRL+SHIFT+I (PC) shortcuts to fix namespaces in the current file.  Much in the same manner, the same shortcut can be used in a Java class to fix all imports.  This shortcut enables easier management of namespaces in XHTML and imports in Java classes.

Figure 1:  Fix imports in Java Class


Figure 2:  Fix namespaces in XHTML



#2 - Autocompletion within XHTML and HTML

Sometimes it is easy to forget the name of that controller class when adding an EL expression to your XHTML view.  Other times we remember the name, but don't want to type out the entire path to the controller and method or property.  NetBeans provides auto-completion for Expression Language within XHTML files to remedy these issues.  Just start typing within an EL expression to see the auto-completion for all of the JSF controllers and/or properties/methods for the current project.


Figure 3:  Auto-completion in Expression Language

#3 - Quick Navigation to controller class or backing bean method

To quickly navigate to a JSF controller or property/method declaration that is referenced within an EL expression, simply hold down the CMD (OS x) or CTRL (PC) button and mouse click on the name.


#4 - Quickly Navigate to JavaScript

To quickly navigate to a referenced JavaScript function, hold down the CMD (OS x) or CTRL (PC) button and mouse click on the reference.
Figure 4: CTRL or CMD + click on function name

#5 - Navigate Directly to Stylesheet

To quickly navigate to a CSS Style, hold down the CMD (OS x) or CTRL (PC) button and mouse click on the "id" or "class" attribute of the element that is referencing the style, and a drop-down list of all matches will be displayed



Figure 5:  CTRL or CMD + click on "id", "class", or "styleClass" attribute
.