Tutorial: Glassfish running Groovy Scripts

2 06 2009

This is my very first screencast. Even I favor to read tutorials with screenshots, I believe it is easier to create screencasts than doing continuously screenshots and writing about them. In this tutorial I create a web application in Netbeans and add a very simple groovy script to it.

Ingredients:

  • Netbeans 6.5.1
  • Groovy 1.6.3
  • Glassfish V2
  • Chrome Browser

The embedded video on this blog does not support fullscreen. For fullscreen follow this link.

This video is created using Camtasia and hosted on screencast.com.

Resume: It is faster once you get used to the tools and talking to the screen ! So excuse me for the simple tutorial and wait for more sophisticated ones.





How to install PostgreSQL on OpenSolaris

31 05 2009

The installation is not straight forward as a double-click “setup.exe” on Windows. I summarized the steps to get a running PostgreSQL 8.3.x installation on OpenSolaris 2008.11. All done using a terminal session. Commands to execute in green.

  1. Login or open terminal as root user.
  2. pkg install SUNWpostgr-83-server
  3. pkg install SUNWpostgr-83-client
    Read the rest of this entry »




Tutorial: Reading from the DB with Netbeans and ZK (Part 2)

24 03 2009

In this part 2 we modify the ZK project from part 1 and add data binding and a detail view.

Before we start adding the new functions, you might want to look in some of the project settings that are default when you create a new ZK360 type web project. Both context path (under Project properties|Run), as well the Display Name in the web.xml (under project explorer|configuration files) . You better change the default to avoid confusion when starting to create the second project.

I recommend to have a look at these 2 documents: ZK Developers Guide and the ZK Reference Doc (link), giving you more insights how ZK works and how feature rich it is. I noticed the available Netbeans palette does not show all available features, so you are better of browsing the docs and look at the sourcecode of the ZK Explorer application (Live Demo).

Back to part 2.

Requirements:

  • Netbeans 6.5 with a running derby DB and the sample database (customer table)
  • Installed ZK 3.6.0 plugin
  • The project from part 1 (link)

Content

1. Open the ZKReadDB project from part 1
2. Change the controller class
3. Activate the Data Binding Manager
4. Make the listbox work witha model and refer the listitems to the fields
5. Implement the detail view
6. Add the detail view with textboxes
7. The complete index.zul and controller.java

Read the rest of this entry »





Tutorial: Reading from the DB with Netbeans and ZK

21 03 2009

After the first very basic tutorial that gets you started with the required plugins and settings (link), I will summarize in this tutorial how display data with zul using the JPA.

Requirements:

  • Netbeans 6.5 with a running derby DB and the sample database (customer table)
  • Installed ZK 3.6.0 plugin

Tutorial:

Content:
1. Start a new project
2. Create a new Entity Class from Database
3. Create a Controller
4. Create the table

Read the rest of this entry »





How to get started with Prefuse and Netbeans

30 01 2009

I was looking for a java based visualization toolkit for quite a while. Either they are very static (image rendered and delivered without any interaction) or cost too much money or badly documented or plain buggy and incomplete. I found a toolkit called prefuse (link) on sourceforge which is an amazing piece of work done by Jeffrey Heer (link) of Berkeley University Stanford. Thanks for this and to the people in the forum (link) to continue the effort to answer questions.

Though it’s last release if dating 2007.10 it is feature complete and not really need to carry the beta tag, but never mind. The project migrated to flare (link) based on Flash and AS, but unfortunately that is not always the first choice, even more powerful in terms of graphics. But I wonder what would be missing. It is open source, so with community effort things can be implemented or even added.
It is released under BSD and can be used freely for commercial and non-commercial applications.

I am a true Netbean nerd, aka NB user and spent some time to get started with prefuse.

Today I wan to share with you the steps (i did) to get a running with prefuse and Netbeans running Windows.
(Please note, it might not be the perfect or smartest approach. I dont claim its the right way or complete, but I got it to work this way. )
I am sure this is very basic information for the prefuse experts, but other beginners might need to go through the same steps.

1. Donwload the file prefuse-beta-20071021.zip (link).

2. Unzip the file to folder.

3. Check for a properly set JAVA_HOME path, like

E:\Documents and Settings\SAM>echo %JAVA_HOME%
E:\Program Files\Java\jdk1.6.0_10

4. Open the file build.bat with text editor of your choice and change the follwoing line
%JAVA_HOME%\bin\java.exe -Dant.home=…
to
java.exe -Dant.home=…
(I removed the JAVA_HOME because java already is in the system PATH)

5. Open a DOS-Box (Windows, aka run.. CMD) and navigate to the folder with the build.bat file.

6. Execute ‘build.bat all’. You should get something like this:

Build

prefuse and Netbeans: Build the jarfiles

7. Start Netbeans and create a new project (New, Choose project, Java, Java Application). Lets call it PrefuseDemo.

8. Open the project properties (right click on the project name in the project explorer) and select properties. Go to the libraries sectio and add prefuse.jar and demo.jar (required for the sample code). You find these files in the folder ‘build’ created by our build.bat.

9. Now you change the packagename (with the initial created Main.Java if selected) to prefusedemo.

10. In the build folder you also find a src folder with various sample java code. For this tutorial I took GraphView.java.

11. Create a new javaclass in the prefuse package with the name GraphView.

12. Copy the complete sourcecode from GraphView.java into it and replace the basic skeleton.

13. Fix the package name to package prefusedemo;

14. You can delete the Main.java if NB created it for you.

15. Build the project.

16. Right click onGraphView.java and select Run File. Finished ! You should see this:

t200901300014

prefuse and Netbeans: Run the demo


Remarks:
1. The other files (demos that come with the prefuse package) you can create the same way and add them into your demo application.
2. I tried to import the whole prefuse source folder into Netbeans via Import, but it didnt work.

Conclusion:
Now we got started, lets move on to understand the prefuse concept and adapt some of the samples to our own applications or create new ones from the scratch ! Stay tuned for more prefuse !





Tutorial: Starting with Glassfish and JMS (Part 2)

9 01 2009

Today we proceed with last weeks JMS tutorial and create a standalone java application that sends a message to a topic.

It puzzles me to have a client application that I need to start “from within”. Lets find out how an application looks like that can run by itself, connect to a JNDI server and sends a message to topic. The key information I took from this discussion (link, Thanks to Foli and TravelEntity) at forums.sun.com.

Using: Netbeans 6.5 and a local Glassfish V2

1. Lets create a standard SE java project. We call it “JMSClient”

tut09010005_new_java_application

JMSClient: New Java SE project

2. Import the necessary libraries

Applicationserver JNDI Lookup
/lib/appserv-rt.jar
/lib/appserv-admin.jar
/lib/javaee.jar
/lib/j2ee.jar

Client Lib
/imq/lib/jms.jar
/imq/lib/imq.jar
/imq/lib/imqutil.jar
/lib/install/applications/jmsra/jmsra.jar

(You find them in your glassfish home directory)

Libraries

JMSClient: Libraries

3. The complete source


package jmsclient;

import java.util.Hashtable;
import java.util.Queue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Main {

    public static void main(String[] args) {

        Context jndiContext = null;
        ConnectionFactory connectionFactory = null;
        Connection connection = null;
        Session session = null;
        // ---- Same sample with a queue ----
        // Queue queue = null;
        Topic topic = null;
        MessageProducer messageProducer = null;
        MapMessage message = null;

        Hashtable properties = new Hashtable(2);
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
        properties.put(Context.PROVIDER_URL, "iiop://localhost:3700");

        try {
            jndiContext = new InitialContext(properties);
            connectionFactory = (ConnectionFactory)jndiContext.lookup("jms/ConnectionFactory");
            // ---- Same sample with a queue ----
            //queue = (Queue)jndiContext.lookup("jms/Queue");
            topic = (Topic)jndiContext.lookup("jms/Topic");

            connection = connectionFactory.createConnection();
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            // ---- Same sample with a queue ----
            //messageProducer = session.createProducer(queue);
            messageProducer = session.createProducer(topic);
            message = session.createMapMessage();

            // ---- Preparing Mapped Message ----
            message.setString("lastname", "Myer");
            message.setString("firstname", "Fred");
            message.setString("id", "0200");

            messageProducer.send(message);

            connection.close();

        } catch (NamingException e) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
        }
        catch (JMSException e) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
        }
        finally {
            System.out.println("ENDED.");
            System.exit(0);
        }
    }
}

Remarks:

  • The tutorial is looking for a local server. Change (Context.PROVIDER_URL, “iiop://localhost:3700″) to the relevant server and port info.
  • We use a topic (publish/subscribe) in this sample. If you want to use a queue instead, change to the lines which are commented out and remove the topic related lines.




Tutorial: Starting with Glassfish and JMS

3 01 2009

Despite tons of material, downloads and websites on JAVA enterprise applications, tools and features, there are few sources only for “Let’s get started” styled tutorials. The Netbeans tutorial is often the best starting point (link).

I was reading about the background of JMS, some of the material is of a very theoretical nature and I tried to find some simple sample to get my hands dirty. A good short article on JMS in the glassfish context you can find at java.net (link)

This tutorial describes the steps to get a most simple messaging application up and running implementing a one-to-many communication using topics, also called publish-subscribe. A enterprise client creates a message put it on a topic and a message-driven bean (MDB) retrieves the message.

Using: Netbeans 6.5 with installed Glassfish V2.

1. Creating a new JAVA EE project.

MyJMS Project

MyJMS Project: New Project

2. We call it MyJMS. Disable the web-application and enable application-client

My

MyJMS Project: New EE Application

3. We will have a project window with 2 subprojects for the EJB and the application client.

d

MyJMS Project

4. Before we start with the coding of the EJB and the client, we configure the applicationserver. Open the admin console via right click on the application server under services (Start the server first, if not done yet). You remember the default admin password for glassfish ? “adminadmin”.You better change if your box is open to outside world.

tut09010003_

MyJMS: View Admin Console

In the admin console we create the ressources for the JMS topic.

tut09010006_

MyJMS: Add Resources

Create a destination resource with JNDI name “jms/topic” and Resource type “javax.jms.topic” (rest default settings).
Create a connection factory with the JNDI name “jms/TopicFactory” (rest default settings, but remove username and password).

Read the rest of this entry »





JavaFX 1.0: Get Started

22 12 2008

The few steps it took me to get started with JavaFX. I am using Netbeans 6.5, so the only thing to do is to select the plugins under Tools and reload the catalog for available plugins. Search for “javafx” and install the 4 plugins/packages.

JavaFX

Install JavaFX Plugins

You might run into this network related problem. It can be annoying because you eventually have to start the 45MB download again (and again), but that applies to all plugins.
Not all of the plugins have been successfully donwloaded..

javafx2

Network Problem

After downloading and restarting the IDE you find 2 new sections in the “new peoject” screen. One for a skeleton JavaFX application and under samples a rather big number of preloaded samples to get you running. Read the rest of this entry »