在 Windows 启动时自动启动 Java 应用程序的代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1025807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:51:10  来源:igfitidea点击:

Code for Auto starting a java application on windows startup

java

提问by Bhavi

Possible Duplicate:
Auto startup for java desktop application?

可能的重复:
Java 桌面应用程序的自动启动?

I have a Java desktop application using netbeans 6.5.1. I was wondering if anybody can help me in suggesting code for autosatrting the Jar file on windows start up.

我有一个使用 netbeans 6.5.1 的 Java 桌面应用程序。我想知道是否有人可以帮助我建议在 Windows 启动时自动加载 Jar 文件的代码。

Thanks in advance Bhavi

提前致谢 Bhavi

回答by Thorsten Dittmar

It depends on what you mean by "Windows Startup". Running it in the background without a user logging in, you'd have to create a Windows Service wrapper.

这取决于您所说的“Windows 启动”是什么意思。在没有用户登录的情况下在后台运行它,您必须创建一个 Windows 服务包装器。

In case "Windows Startup" means "run when the user logs in", create a batch file that starts your application and put a link to that batch file into the user's Autostart folder (or the "All Users" Autostart folder).

如果“Windows 启动”的意思是“在用户登录时运行”,请创建一个批处理文件来启动您的应用程序,并将指向该批处理文件的链接放入用户的自动启动文件夹(或“所有用户”自动启动文件夹)。

EDITTo clarify what I mean according to your comments.

编辑根据您的评论澄清我的意思。

You said you were a .NET programmer, so we can just talk like you'd develop a .NET application:

你说你是一个 .NET 程序员,所以我们可以像你开发 .NET 应用程序一样交谈:

  1. If your program should behave like a Windows Service, you'd need some kind of service wrapper that acts as the "real" Windows service and starts your program when it is started using the Service Manager (you can not develop a Windows Service in Java so far, so you need this wrapper).

  2. If your program should behave like a normal application and just be started whenever a user logs on (example: Skype or WinAmp Agent), you'll just have to start your program putting a link to it into the user's AutoStart folder.

  1. 如果您的程序应该像 Windows 服务一样运行,那么您需要某种服务包装器作为“真正的”Windows 服务,并在使用服务管理器启动程序时启动您的程序(您不能在 Java 中开发 Windows 服务)到目前为止,所以你需要这个包装器)。

  2. 如果您的程序应该像普通应用程序一样运行并且在用户登录时启动(例如:Skype 或 WinAmp Agent),您只需启动您的程序,将指向它的链接放入用户的 AutoStart 文件夹。

In case of 1), you'd have to follow the answers of the other posters - I've never done that myself before, but I'm sure it can be done. (Maybe this link will help you: http://edn.embarcadero.com/article/32068)

在 1) 的情况下,您必须遵循其他海报的答案-我自己以前从未这样做过,但我确信可以做到。(也许这个链接会帮助你:http: //edn.embarcadero.com/article/32068

In case of 1), just create a batch file that runs your application and create a link to that batch file in the user's/All Users' AutoRun folder.

在 1) 的情况下,只需创建一个运行您的应用程序的批处理文件,并在用户/所有用户的 AutoRun 文件夹中创建指向该批处理文件的链接。

回答by akarnokd

We use Windows-Tomcat's tomcat6w.exe (renamed to OurApplication.exe) to create a service for our Java application. Then we just set it to autostart.

我们使用 Windows-Tomcat 的 tomcat6w.exe(重命名为 OurApplication.exe)为我们的 Java 应用程序创建服务。然后我们只需将其设置为自动启动。