Thursday, October 31, 2013

Eclipse RCP Packaging and Deployment for Java Web Start

Following the tutorial on Eclipse RCP and Database Connection Example, we're going to package this plug-in and deploy on a web/app server for Java Web Start.

Step 1: Create a feature project named com.icode.rcp.demo.feature 


Step 2: Add Plug-ins and Included Features into com.icode.demo.feature


Step 3:  Export the feature project for Java Web Start


Note: exporting may take some time. So be patient!

Step 4: Deploy to a server (Web server or App server), tomcat 7 is used for this example
- create a start.jnlp as shown:

- go to your browser: http://localhost:8080/demo/start.jnlp (Sometimes, this is not working, you may try this from the terminal: javaws http://localhost:8080/demo/start.jnlp


- it works!

Your hard work is paid off! Enjoy it!?


Note: if you run into some errors like resources (jar files) not found, you may try to comment out those jar files in .jnlp files that located at features folder.


Eclipse RCP and Database Connection Example



In this tutorial, we’re developing an Eclipse Plugin project that connects to a database (HSQLDB) and display the data from the table in the database.

SET 1: SET UP ECLIPSE FOR PLUG-IN DEVELOPMENT

1.  Install Eclipse SDK:

For this tutorial, Eclipse Indigo (3.7) is used, install Eclipse RCP Plug-in Developer Resources* as shown

STEP 2: CREATE ECLIPSE RCP Plug-in PROJECT NAMED com.icode.rcp.demo

1. New > Plug-in Project 



2. Run test the Plug-in

Right click on com.icode.rcp.demo > Run As > Eclipse Application (or open plugin.xml > Overview > Launch an Eclipse application)


So far so good!... the Plug-in is running. Now let's add a view into the GUI.

3. Add a view to the Plug-in


 - plugin.xml > Extensions > Add > org.eclipse.ui.views



- right click on org.eclipse.ui.views > New > view
 - fill info as shown (click on class to create the class CustomerView)



4. Activate the view:
 - add this line into the CustomerView.java
            public final static String ID = "com.icode.rcp.demo.views.customer";
- add this into Perspective.java
          String editorArea = layout.getEditorArea();
         layout.setEditorAreaVisible(false);
         layout.addView(CustomerView.ID, IPageLayout.LEFT, 1.0f, editorArea);

as shown


5. Run test the plug-in for the newly-create view



So far so good!... Let's move on to the next step.


STEP 3: CONNECT TO THE DB

1. Setup HSQLDB
- download hsqldb and start up the server
- create CUSTOMER table 
- insert these sample data
as shown

      



2. Create class Customer.java and CustomerProvider as follows



3. Create class JdbcUtil.java  as shown



If you run test JdbcUtil.java now, you will get this error:


To fix that error, we need to add hsqldb.jar into the com.icode.rcp.demo class path. In order to that, we have to create another plugin project. Let's do it.

4.  Create a plugin project from existing archive named org.jdbc.hsqldb as shown:


5. Export org.jdbc.hsqldb into the target location 

Note: make sure org.jdbc.hslqd plugin shown up in the target definition as shown (You may have to restart your Eclipse if reloading  not working)




6. Add org.jdbc.hsqldb into com.icode.rcp.demo project as a dependency


Run test JdbcUtil.java again





So far so good! The back end of the plug-in (com.icode.rcp.demo) can connect to the db. Now let’s modify the views to display the data from the db.

7.  Modify the CustomerView



8. Run test the plugin com.icode.rcp.demo



There you go! Now you have a Eclipse Plugin app connected with the db. Enjoy it!

Note: Along the process, if you run into the following error. Don't panic. 

error - could not found in the registry

solution: clean project, or restart Eclipse