windows 如何让 Java 应用程序在 PC 启动时自动启动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4565639/
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-09-15 15:52:35  来源:igfitidea点击:

How to make a Java app automatically start when PC starts?

javawindows

提问by Frank

I'm developing a scheduling app, it reminds user of things to do during a day, it checks every minute to see if time is up, and if it is it will open an alert window to remind the user. Although it's written in Java, I'm targeting Windows users for this app. It needs to run as soon as users' PCs are turned on, so my question is: How to make a Java app automatically start when a PC is turned on in a Windows system?

我正在开发一个日程安排应用程序,它会提醒用户一天中要做的事情,它每分钟检查一次,看看时间是否到了,如果时间到了,它会打开一个警报窗口来提醒用户。尽管它是用 Java 编写的,但我针对此应用程序的目标用户是 Windows 用户。它需要在用户的PC一打开就运行,所以我的问题是:如何使Java应用程序在Windows系统中打开PC时自动启动?

I know I can go through a few steps manually to add the app to start-up apps list, but not every user is familiar with the steps, so I wonder if it can do this through my Java program, and if so is there any sample code?

我知道我可以手动通过几个步骤将应用程序添加到启动应用程序列表,但不是每个用户都熟悉这些步骤,所以我想知道它是否可以通过我的 Java 程序来完成,如果可以,有没有示例代码?

采纳答案by KitsuneYMG

create a .bat file

创建一个 .bat 文件

@javaw -jar path/to/jar/Name.jar arguments

drop this in you startup directory

把它放到你的启动目录中

回答by Chandra Patni

Use Java Service Wrapper. Set wrapper.ntservice.starttype=DEMAND_STARTin wrapper configuration.

使用Java 服务包装器wrapper.ntservice.starttype=DEMAND_START包装器配置中设置。