JavaExe and Java application as windows system service interactive to desktop(JavaExe 和 Java 应用程序作为与桌面交互的 Windows 系统服务)
问题描述
请求:
这是我所在地区的 Java 开发人员面临的一个非常常见的问题.我真的被困了很多天.搜索并尝试了很多,阅读文档.阅读所有与 JavaExe 相关的 stackoverflow 问题.请仅在您以前做过类似的事情并有全面答案的情况下回复.我会非常感谢社区!
This is a very common problem faced by Java devs in my locale. I am really stuck for many days on this. Searched and tried a lot, read the docs. read ALL the stackoverflow questions related to JavaExe. Please only reply if you have done similar thing before and have a comprehensive answer. I would be really grateful to the community!
塞纳里奥:
我正在使用 JavaExe 将应用程序作为 系统服务 在桌面 交互式 功能中运行.确切地说,我有一个捕获桌面屏幕截图的应用程序.我希望它在任何用户登录时运行(以管理员身份),因此没有人可以阻止它.
I am using JavaExe to run an application as system service in desktop interactive capability. To be exact I have an application that captures screenshots of desktops. I want it to run (as admin) on any user login so no one can stop it.
我有一个 myapp.jar、settings.txt 和一个 lib 目录.
I have a myapp.jar, settings.txt and a lib dir.
我搜索了很多,发现 JavaExe 有效(通过观看它的示例)
I have searched alot and found JavaExe works (by watching its examples)
如果有人有更好的方法.请说明.
If anyone has a better way. Please state so.
问题:
根据我的研究,
你必须创建一个类似.exe 的.properties 文件,并在该文件中写入
"RunType = 1"
.
您在主类中定义了一个静态方法:serviceInit()
you define a static method in your main class : serviceInit()
我需要放置任何类或引用/导入吗?怎么样?
Do I need to place any class or reference/import? How?
我下面的代码 works 作为独立的 .jar 和 javaExe.exe.
My code below works as stand alone .jar and in javaExe.exe too.
它现在提供系统服务并由SYSTEM用户运行.但它不能与桌面交互.即它没有显示任何 GUI.
It now does makes a system service and runs by as SYSTEM user. but It is NOT interactive to desktop. i.e its not showing any 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 中是不可能的?
And I dont think that bundling the .jar, lib directory and settings.txt into one .exe is possible?
推荐答案
你应该有:
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"
};
}
}
这篇关于JavaExe 和 Java 应用程序作为与桌面交互的 Windows 系统服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JavaExe 和 Java 应用程序作为与桌面交互的 Windows 系统服务
基础教程推荐
- Java:带有char数组的println给出乱码 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01