gpt4 book ai didi

java - 使用 cronjob 运行 JAVA 的 Linux 命令

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:31 24 4
gpt4 key购买 nike

我正在尝试设置一个 cronjob (cPanel) 来执行将运行 java 应用程序的 shell 文件。但是我无法使类路径起作用。

JAVA文件夹应用路径

/home/user/public_html/version_1/data/downloader

.sh 文件中的这个命令在通过终端和 JAVA 应用程序文件夹中运行时有效

java -cp .:download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar portal.client.Main login

但是,当在文件夹外运行时,它不起作用并返回以下错误

Error: Could not find or load main class portal.client.Main

所以我尝试特定的类路径

java -cp /home/user/public_html/version_1/data/downloader/*:.download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar th.or.set.portal.client.Main login

还是报错

log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:297)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315)
at portal.client.Main.main(Main.java:32)
log4j:ERROR Ignoring configuration file [log4j.properties].
log4j:WARN No appenders could be found for logger (portal.controller.MainController).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:117)
at portal.client.DownloadParameter.parseLoginParam(DownloadParameter.java:177)
at portal.controller.MainController.execute(MainController.java:45)
at portal.client.Main.main(Main.java:130)

最佳答案

嗯。您需要更改工作目录。您可以简单地使用 cd 来完成。

cd /home/user/public_html/version_1/data/downloader/
java -cp .:download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar portal.client.Main login

关于java - 使用 cronjob 运行 JAVA 的 Linux 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39247000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com