Tuesday, December 17, 2013

Java Configuration on Windows Machine

For a regular user, all you need is JRE (Java Virtual Machine) to execute Java Application that is already compiled. To install this JRE, when you download the installer from Oracle website. This JRE is used by Windows system and the default browser (i.e. Internet Browser).

For a developer, you would need to java compiler (javac), a.k.a JDK. Recently, Oracle bundles it with application server Glassfish called SDK.

To created environment variable JAVE_HOME
Add JAVA_HOME into variable PATH

Start > cmd >
java -version
javac -version

This java version may be different with java version used by the default browser and java control panel in Windows control panel.

Monday, December 16, 2013

How to get JDK/SDK as a zip file

You're probably like me... just don't want to use installer since it may mess up your system configuration.
However, since late version of Java 6, Oracle no longer offer JDK/SDK as a zip file, but a installer. So how do you get the zip file?
Here is the tricks:

Trick 1:
Download the installer from Oracle (e.g. EE 7 SDK) and install on a lab machine (Windows machine) and then go this location:

C:\Users\YourUsername\AppData\Local\Temp\java_ee_sdk-7-jdk7-windows-x64.exe\Product\Packages

grap jdk7.zip file.

Trick 2:
 Just extract the installer itself (e.g. java_ee_sdk-7-jdk7-windows-x64)

 Go to /Product/Packages and the jdk.zip shoudl be there!


That's it. Easy as that.




Note: Linux box, you may try open jdk.

Thursday, December 12, 2013

Raspberry PI: Get started!

Alright, you just have bought Raspberry PI toy. So what's you gonna do with it? Here's what I did:

1. download this utility (app) if you're using Windows:
 http://sourceforge.net/projects/win32diskimager/

2. download this image and save into your machine:
http://downloads.raspberrypi.org/raspbian_latest

3. plug the SD card into your Windows machine

4. run Win32Imager app: browser to the image file you just downloaded, choose the correct disk name for the SD (mine is E), and hit next (wait for 3-5 min for it to be done)

5. Now plug the SD with Raspbian OS into the Raspberry PI toy and power it on

That's it. It's just quick and easy! Enjoy your new toy!

Note:
1. to use the Raspberry PI behind the proxy for apt-get command, create a file named proxy under/etc/apt/apt.conf.d/ and add this following text line:
Acquire::http::proxy=http://yourproxy.com:port/
2. Keyboard issue: by default the keyboard layout is GB (Great Britain), so when you type <shift>+3, it does NOT show # instead of English pound sign. The same issue with <shift>+2. You can fix the keyboard issue:
sudo nano /ect/default/keyboard
change GB  > US
3. To insall apache2 and php5:
sudo ap-get install update
sudo apt-get install apache2 php5 libapache2-mod-php5
sudo service apache2 restart (apache2 started right after it's installed, you have to restart it here)
apache installation location: /etc/apache2
apache web dir location: /var/ww



Friday, December 6, 2013

Godaddy site: how to test webformmailer

webhosting > launch > hosting > More > form mail>
enter from email address:

then test the mailer

Apache CGI 101

Apache pre-installed on Mac OSX 10.7.5 and CGI is already configured in apache config file.
/private/etc/apache2/httpd.conf

Just place your cgi scripts under: /Library/WebServer/CGI-Excecutables

On your web browser, go to: http://localhost/cgi-bin/test.cgi *

Check apache log file: tail -f  /var/log/apache2/error_log

Start/stop/restart apache instance: sudo apachectl start/stop/restart


* Note: cgi-bin alias must be part of url, otherwise you will get error (files does not exist in the error log). This mistake is very common for beginners to overlook and caused a lot of headache! It took me hours and hours to realize this mistake. At first, I thought some wrong with apache config file and/or with cgi program.

---------------------------
If you want to test ssi exec cgi script in html for your website hosted by godaddy.com, it will not work due to security reason.

Windows: how to turn off login screen

For Windows 7 (Pro version) and 8, use this command
Ctrl + R
control userpasswords2
then uncheck: Users must enter a username and password to use this computer

For Windows 8 on Surface tablet, use a different command:
Search (no Ctrl+R for tablet!)
netplwiz

Friday, November 8, 2013

Linux: check directory free space command

Let's say you want to check free space at /tmp. Here's the command:
df -lkh /tmp

l: local - limit listing to local file systems
k: block size: 1K
h: human readable


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