Running Client part of Java Enterprise Application using a batch file

Below is a simple way of running the client part of a J2EE application, by creating a batch file. Some assumtions made are :

1. JDK is installed on the Computer

2. Glassfish is installed and the EJB module deployed

To create a batch file, open notepad.exe, type your need commands and save your file as filename.bat

Below is the content of the batch file

Rem the portion below starts the Glassfish server if it has been shutdown

cd C:\Sun\SDK\lib
call “C:\Sun\SDK\config\asenv.bat”
call “%AS_INSTALL%\bin\asadmin.bat” start-domain domain1

goto e

Rem the portion below call the jar file, by going to its directory and

Rem calling the full class name (including package name of the start up file

cd c:\
cd C:\sabon\eduSSS
appclient -client EducationSSSClient.jar -mainclass com.sabonay.educationSss.ui.LoginForm
goto end


Below is a picture after running the script




It is sometimes troublesome to save and retrieve images in  a database using java. Below are methods that are useful in saving and retrieving images from a database

To save an image in a database the datatype of the column should be “blob”. One thing to note is that in the EJBs the blob datatype is change to an array of bytes (“byte[]”)

A function to change an image file into its bytes

public Function byte[] setImagebytes(File imageFile) {

byte[] imagebytes = null;

try {

FileInputStream fis = new FileInputStream(imageFile);

imagebytes = new byte[(int) imageFile.length()];;

} catch (FileNotFoundException ex) {


} catch (IOException ex) {



Return imagebytes;


A method to browse for an image file from its location and show it in a label

private void btBrowseActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

// a method to browse for a picture and pass the image file to the setImagebytes method

fc.setFileFilter(new FileNameExtensionFilter("Images", "jpg", "gif", "bmp"));

if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {


ImageIcon icon = new ImageIcon(fc.getSelectedFile().getAbsolutePath());

icon = new ImageIcon(icon.getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));


//passing the image file to the setImagebytes to create the image bytes






A method to convert the bytes array (byte[]) into a pictures to display in a label

Private void getRealImage(byte[] imagebytes){

if (imagebytes != null) {

ImageIcon icon = new ImageIcon(imagebytes);

icon = new ImageIcon(icon.getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));


} else {

ImageIcon icon = new ImageIcon();

//showing the image in a label