Solved JavaExe.exe not opening the GUI

December 31, 2013 at 21:26:20
Specs: Windows 7
Hi
I am using JavaExe.exe for launch my Java program as a Windows service.
I renamed JavaExe.exe with my jar name.
I created a resource folder in my application path.In that i created jre folder and copied jre files.
After that I created property file ,in that i added details JRE version = 1.2 RunType = 1 Main Class=className.
I used UpdateRsrcJavaExe to integrate .property file with .exe.
When i typed MyApp.exe -installService ,the service started.But my GUI not getting up.
Could anyone please help me to solve this issue.Or Did I skipped any step??
As am very urgent to solve this issue, please do reply ASAP.

Regards
Divya


See More: JavaExe.exe not opening the GUI

Report •


✔ Best Answer
January 2, 2014 at 11:26:16
In your case, you must create a class named : Activator_TaskbarManagement (if Activator is the name of your main class).

First, in this class you can define these methods (No main() method) :

=> to manage a menu associed with icon :
taskGetMenu(),
taskGetDefaultMenuID(),
taskDoAction(),
taskDisplayMenu()

=> to manage the balloon info :
taskDoBalloonAction(),
taskIsBalloonShow(),
taskSetBalloonSupported(),
taskGetBalloonInfo()

=> to show, or not, the icon :
taskIsShow()

=> to communicate with service :
taskDataFromService(),
taskIsDataForService(),
taskDataForService()

Read the documentation, page 37.


Then, in your main class Activator (or a class named Activator_ServiceManagement), you can define these methods :

=> to create or remove the service :
serviceIsCreate(),
serviceIsLaunch(),
serviceIsDelete(),
serviceGetInfo()

=> to pause or stop the service :
serviceControl_Pause(),
serviceControl_Continue(),
serviceControl_Stop(),
serviceControl_Shutdown()

=> to init the service at launching :
serviceInit(),
serviceFinish()

=> to communicate with taskbar for UI part :
serviceDataFromUI(),
serviceIsDataForUI(),
serviceDataForUI()

It's preferable to use serviceInit() instead of main() method.
Read the documentation, page 23.

Read also the sources of examples 5, 8, 23 to have a concrete example.



#1
January 1, 2014 at 05:49:53
to have an interactive service, you must define a class named XXX_TaskbarManagement (where XXX is the name of your main class).
There are many examples, and documentation, in the JavaExe.zip

Report •

#2
January 1, 2014 at 20:53:04
Hi

Thanks for your response.
I tried to execute example "5 - Service & TrayIcon" in JavaExe.
But the same pblm I am not able to see GUI part.
I am using Windows 7.

Thanks in Advance
Divya R Dharan


Report •

#3
January 2, 2014 at 01:34:36
Hi Albert,

I tried to execute example 8. It worked fine.
I am creating a Eclipse RCP project.
In this Activator class is the starting point.
For making my application as service ,as u told I have to write XXX_TaskbarManagement class.
But could you please tell what should I write in this class.
Is it necessary to have a class with main method?

Waiting for ur reply

Rregards
Divya R Dharan


Report •

Related Solutions

#4
January 2, 2014 at 11:26:16
✔ Best Answer
In your case, you must create a class named : Activator_TaskbarManagement (if Activator is the name of your main class).

First, in this class you can define these methods (No main() method) :

=> to manage a menu associed with icon :
taskGetMenu(),
taskGetDefaultMenuID(),
taskDoAction(),
taskDisplayMenu()

=> to manage the balloon info :
taskDoBalloonAction(),
taskIsBalloonShow(),
taskSetBalloonSupported(),
taskGetBalloonInfo()

=> to show, or not, the icon :
taskIsShow()

=> to communicate with service :
taskDataFromService(),
taskIsDataForService(),
taskDataForService()

Read the documentation, page 37.


Then, in your main class Activator (or a class named Activator_ServiceManagement), you can define these methods :

=> to create or remove the service :
serviceIsCreate(),
serviceIsLaunch(),
serviceIsDelete(),
serviceGetInfo()

=> to pause or stop the service :
serviceControl_Pause(),
serviceControl_Continue(),
serviceControl_Stop(),
serviceControl_Shutdown()

=> to init the service at launching :
serviceInit(),
serviceFinish()

=> to communicate with taskbar for UI part :
serviceDataFromUI(),
serviceIsDataForUI(),
serviceDataForUI()

It's preferable to use serviceInit() instead of main() method.
Read the documentation, page 23.

Read also the sources of examples 5, 8, 23 to have a concrete example.


Report •

#5
January 3, 2014 at 01:34:25
Hi Albert,

I created one application ,which is opening a dialogue.
I created 3 classes for this.
ServiceTest.java (Main),
ServiceTest_TaskbarManagement.java ,
ServiceTest_ServiceManagement.java

But my doubt is in the static block in ServiceTest_TaskbarManagement.java class,
which functon will I call??
I wants to make my app as service and at the same time the UI (Dialogue ) of my Application should be visible.

ServiceTest.java
===============
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.GridLayout;

public class ServiceTest {

public static void createAndShowGUI() {

JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Bundle Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel(new GridLayout(0, 1));
JButton button = new JButton("Dummy Button!");
pane.add(button);
JLabel label = new JLabel("Example for Bundling JRE with Java Class");
pane.add(label);
pane.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
frame.getContentPane().add(pane);
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}

}

ServiceTest_TaskbarManagement.java
==============================
import java.io.Serializable;
import java.util.Vector;

import com.devwizard.javaexe.interfaces.JavaExe_I_TaskbarManagement;


public class ServiceTest_TaskbarManagement implements JavaExe_I_TaskbarManagement {
static final int ID_MENU_LOG = 1;
static final int ID_MENU_SHOW = 2;

static boolean isShowDetails = false;
static boolean isShowBalloon = true;
static boolean isDataBalloon = true;
static boolean isBalloonSupported = true;
static boolean isFirstBalloon = true;

static Object lockBalloonData = new Object();
static String lastBalloonData = null;
static String balloonIcon = ""+NIIF_USER;
static String balloonData = "ServiceTest";


/*******************************************/
/* public static String[][] taskGetMenu(boolean isRightClick, int menuID)
{
if(!isRightClick || menuID > 0)
return null;

return new String[][]
{
{ ""+ID_MENU_LOG, "Open Log", "", (ServiceTest.isShow() ? ""+MFS_DISABLED : "") },
{ ""+ID_MENU_SHOW, "Show Balloon", "", (!isBalloonSupported ? ""+MFS_DISABLED : (isShowBalloon ? ""+MFS_CHECKED : "")) },
};
}*/

/*******************************************/
public static int taskGetDefaultMenuID(boolean isRightClick)
{
return ID_MENU_LOG;
}

/*******************************************/
/* public static void taskDoAction(boolean isRightClick, int menuID)
{
switch(menuID)
{
case ID_MENU_LOG :
if(Example8.app != null) Example8.app.setVisible(true);
break;

case ID_MENU_SHOW :
isShowBalloon ^= true;
break;
}
}*/

/*******************************************/
public static void taskDoBalloonAction()
{
if(lastBalloonData != null && !isShowDetails)
{
isShowDetails = true;
Examples_UtilsGUI.showInfoDialog("Details", lastBalloonData);
isShowDetails = false;
}
}

/*******************************************/
/* public static void taskInit(boolean isServiceUI)
{
Example8.createApp();

if(Example8.app != null)
Example8.app.setVisible(true);
}*/

/*******************************************/
public static String[] taskGetInfo()
{
return new String[]
{
"JavaExe : ServiceTest" // Description
,""+ACT_CLICK_MENU // action "1 click-Right"
,""+ACT_CLICK_NOP // action "2 click-Right"
,""+ACT_CLICK_NOP // action "1 click-Left"
,""+ACT_CLICK_OPEN // action "2 click-Left"
};
}

/*******************************************/
/*public static void taskDataFromService(Serializable data)
{
while(Example8.app==null)
try { Thread.sleep(500); }
catch(Exception ex) {}

if(data != null)
{
String[] arr = (String[]) data;

Example8.app.logEvent(arr[0], arr[1]);

if(!isFirstBalloon && isBalloonSupported)
setBalloon(arr);
}
}*/

/*******************************************/
public static void taskSetBalloonSupported(boolean isSupported)
{
isBalloonSupported = isDataBalloon = isSupported;
}

/*******************************************/
public static boolean taskIsBalloonShow()
{
return(isDataBalloon && isShowBalloon);
}

/*******************************************/
public static String[] taskGetBalloonInfo()
{
String[] ret = null;

synchronized(lockBalloonData)
{
isDataBalloon = false;
isFirstBalloon = false;
lastBalloonData = balloonData;

ret = new String[]
{
"JavaExe" // title
,balloonData // text
,balloonIcon // icon type
,"20" // delay in seconds
};
}

return ret;
}

/*******************************************/
static void setBalloon(String[] arr)
{
synchronized(lockBalloonData)
{
balloonData = "New event : "+arr[0];
balloonIcon = ""+NIIF_INFO;
isDataBalloon = true;
}
}


/*---------------------------------------------------*/
/*
static
{
ServiceTest.createAndShowGUI();
}*/
}


ServiceTest_ServiceManagement.java
===========================
import java.io.Serializable;
import java.util.Vector;


public class ServiceTest_ServiceManagement {

static Vector<Serializable> vectData = new Vector<Serializable>();


/*******************************************/
public static boolean serviceIsCreate()
{
return Examples_UtilsGUI.showConfirmDialog("Create Service"
,"Do you want to install the service for SystemEvent ?");
}

/*******************************************/
public static boolean serviceIsLaunch()
{
return true;
}

/*******************************************/
public static boolean serviceIsDelete()
{
return Examples_UtilsGUI.showConfirmDialog("Delete Service"
,"This service is already installed.\nDo you want to delete it ?");
}

/*******************************************/
public static boolean serviceInit()
{
//ServiceTest.createAndShowGUI();
return true;
}

/*******************************************/
public static void serviceFinish()
{
System.exit(0);
}

/*******************************************/
public static String[] serviceGetInfo()
{
return new String[]
{
"JavaExe : ServiceTest" // Full name
,"JavaExe : ServiceTest" // Desc
,"1" // IsAutomatic
,"1" // IsAcceptStop
};
}

/*******************************************/
public static boolean serviceIsDataForUI()
{
return !vectData.isEmpty();
}

/*******************************************/
public static Serializable serviceDataForUI()
{
synchronized(vectData)
{
return vectData.remove(0);
}
}

/*******************************************/
public static void setDataUI(Serializable data)
{
synchronized(vectData)
{
vectData.add(data);
}
}


/*---------------------------------------------------*/

}

Thanks in advance
Regards
Divya R dharan


Report •

#6
January 3, 2014 at 06:11:37
First, you CAN'T run any GUI from service part !
you MUST run any UI elements from *_TaskbarManagement

Then, your main() method in ServiceTest is not necessary because you have already serviceInit() method in ServiceTest_ServiceManagement.
As service, the entry point of your app is serviceInit() method if it's defined.

createAndShowGUI() method must be called only from *_TaskbarManagement, not from serviceInit()


Report •

#7
January 5, 2014 at 20:47:48
Hi Albert,
I tried two ways
Firstly,
I removed main() from my ServiceTest and I called createAndShowGUI() method from *_TaskbarManagement class like
static
{
ServiceTest.createAndShowGUI();
}
But the problem is two process are creating..

Secondly,
I removed serviceinit() from ServiceTest_ServiceManagement class and commented
static
{
ServiceTest.createAndShowGUI();
} in *_TaskbarManagement class.
But in this case UI is not getting up.Only process and service is up.


Could you please help me.
Also I am working in Eclipse plugin project,So there is no main function.The starting point is Activator class,that will automatically done by eclipse.
In this case What will I do ?

Thanks in advance
Divya R Dharan

message edited by drd1988on


Report •

#8
January 6, 2014 at 17:07:51
hello,

it is normal that two processes are created : one for the Service part, and another one for the UI part.

if you remove serviceInit(), then main() that be called (if exist)

if serviceInit() is created, then main() is never called. You can leave main() in ServiceTest for Eclipse.

call createAndShowGUI() from taskInit() or in taskDoAction().


Report •

#9
January 7, 2014 at 09:01:48
Hi Albert
I removed serviceInit from service configuration. And I added main in servicetest class. I couldn't see UI part. Then I tried to cal createAndShowGUI from taskinit() method in taskbarmanagement class. I didn't give serviceinit() function in service management. Now the UI came. Only one process created and one service.
Also when I tried to cal swt dialogue from taskinit, a error message(task could not complete with timely fashion) popped up after some seconds.
Why my main not working if no serviceinit and why hi not coming if main() only in main class
Thanks in advance
Divya

Report •

#10
January 7, 2014 at 19:37:47
hi

don't remove serviceInit()
this method must return TRUE before 30 seconds

you can have also main(), if you want but not necessary, and put :

void main(String[] args)
{
serviceInit();
}

or nothing :

void main(String[] args)
{
}

the entry point of service is serviceInit().

and in your serviceInit() :

boolean serviceInit()
{
//....

return true;
}


Report •


Ask Question