nohup启动jar
时间: 2023-11-11 11:02:58 浏览: 101
可以使用以下命令来在后台启动一个jar包并且不受终端关闭的影响:
```
nohup java -jar yourJarFile.jar > log.out 2>&1 &
```
其中,`yourJarFile.jar`是你要启动的jar包的文件名,`log.out`是输出日志的文件名。
这个命令会将输出重定向到`log.out`文件中,并且在后台运行。如果需要停止这个进程,可以使用`kill`命令。
相关问题
nohup启动jar包
nohup是一个Linux命令,用于在后台运行进程,即使终端关闭也不会停止进程。启动jar包可以使用以下命令:
nohup java -jar yourjarfile.jar &
其中,yourjarfile.jar是你要启动的jar包的文件名。&符号用于将进程放入后台运行。使用nohup命令可以确保即使关闭终端,进程也会继续运行。
nohup 启动jar 不要nohup.out文件
### 如何使用 `nohup` 启动 JAR 文件但不创建 `nohup.out` 日志文件
当使用 `nohup` 命令启动应用程序时,默认情况下会将标准输出和标准错误重定向到名为 `nohup.out` 的文件中。如果希望避免创建此默认日志文件,则可以通过显式地重定向输出来实现。
#### 方法一:将输出重定向至 `/dev/null`
通过将标准输出 (`stdout`) 和标准错误 (`stderr`) 重定向到 `/dev/null`,可以防止任何输出被记录下来:
```bash
nohup java -jar your-application.jar > /dev/null 2>&1 &
```
这条命令的作用如下:
- `2>&1` 表示将标准错误也重定向到与标准输出相同的位置,即 `/dev/null`
- `&` 让程序在后台运行[^1]
这种方法适用于不需要保存任何日志的情况,所有输出都将被丢弃。
#### 方法二:仅捕获错误信息或将日志写入特定位置
如果不希望完全忽略所有的日志信息而是有选择性的处理,比如只保留错误信息或指定其他路径存储日志,那么可以根据需求调整重定向策略:
##### 只记录错误信息
```bash
nohup java -jar your-application.jar >/dev/null 2>error.log &
```
这里只有标准错误会被重定向到 `error.log` 文件中,而正常的标准输出则被抛弃。
##### 自定义日志文件
也可以像下面这样把两个流分别指向不同的地方:
```bash
nohup java -jar your-application.jar >> custom_output.log 2>>custom_error.log &
```
这种方式允许更灵活地管理不同类型的日志数据[^2]。
阅读全文
相关推荐















