请求:
这是Java开发人员在我的区域设置中面临的一个非常常见的问题。我在这件事上被困了很多天。搜了很多遍,读了几本医生的书。阅读所有与JavaExe相关的堆栈溢出问题。如果你以前做过类似的事情,并且有一个全面的答案,请回复。我会非常感谢社会的!
Senario:
我使用JavaExe作为系统服务在桌面交互功能中运行应用程序。确切地说,我有一个应用程序,可以捕捉桌面的截图。我希望它运行(作为管理)在上,任何用户登录,这样就没有人可以阻止它。
我有一个myapp.jar、settings.txt和lib。
我搜索了很多,发现了JavaExe的工作(通过看它的例子)
如果有人有更好的方法。请说明。
问题:
根据我的研究,
"RunType = 1"。serviceInit()是否需要放置任何类或引用/导入?多么?
编辑:
我在下面的代码以独立的.jar和javaExe.exe的形式工作。
现在,确实制作了一个系统服务,并以 system 用户的身份运行。但是It 与桌面并不是交互的。也就是说,它没有显示任何GUI。
package temp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Temp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
serviceInit();
}
public static boolean serviceInit(){
new Thread(){
public void run(){
Integer i = 0;
while(i < 999999999){
JOptionPane.showMessageDialog(null,i);
i++;
}
}
}.start();
return true;
}
}我认为将.jar、lib目录和settings.txt捆绑到一个.exe中是不可能的?
发布于 2013-05-29 19:53:15
你应该在你的情况下:
public class MyApp_ServiceManagement
{
static boolean isMsgToDisplay = false;
/////////////////////////////
public static boolean serviceInit()
{
(new Thread()
{
public void run()
{
for(int i=0;i < 6;i++)
{
try { sleep(5*1000); }
catch(Exception ex) {}
isMsgToDisplay = true;
}
}
}).start();
return true;
}
/// is Data ready to be send to the UI ?
public static boolean serviceIsDataForUI()
{
return isMsgToDisplay;
}
/// Data to be send to the UI
public static Serializable serviceDataForUI()
{
isMsgToDisplay = false;
return "hello, I am an interactive Service";
}
}对于UI部分:
public class MyApp_TaskbarManagement
{
/// To show (or not) the icon in tray
public static boolean taskIsShow()
{
return false;
}
/// Receive the message from Service
public static void taskDataFromService(Serializable data)
{
JOptionPane.showMessageDialog(null, data);
}
/// descr of UI
public static String[] taskGetInfo()
{
return new String[]
{
"UI part of Service"
};
}
}发布于 2013-05-29 15:59:40
main()方法永远不会在服务模式中调用(除了一种特殊情况),但是如果要保留main()方法,必须在serviceInit()中调用main()。
将serviceInit()放在主类中,或者放在另一个名为XXX_ServiceManagement的类中,其中XXX是主类的名称。
然后,serviceInit()必须在延迟30秒之前返回。不要有无限的循环,.在里面。将代码放在线程中,并从serviceInit() (或main)启动它。
你问题的答案?
https://stackoverflow.com/questions/16815956
复制相似问题