Unable to access jar file xxx.jar

最近在编写自动重启某个jar包的shell脚本的时候,老是报错“unable to access jarfile ***.jar ”--不能访问jar包,奇怪啊,怎么会找不到jar包呢!google一把,说是启动jar包的路径不全,shell脚本找不到。

      修改了jar包的启动路径,如下:/usr/local/japp/jre16/bin/java -jar /usr/local/japp/****/***.jar,按照网上说的应该没有问题了,执行脚本,继续报错:

         + /usr/local/japp/jre16/bin/java -jar /usr/local/japp/××××/×××.jar
com.cplatform.sms_notice.client.MainEntry main
信息: 系统启动失败:java.io.FileNotFoundException: ./config/sys.properties (No such file or directory)
java.io.FileNotFoundException: ./config/sys.properties (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at com.cplatform.config.PropertiesConfig.loadValues(PropertiesConfig.java:131)
        at com.cplatform.config.FileConfig.reload(FileConfig.java:155)
        at com.cplatform.config.FileConfig.<init>(FileConfig.java:62)
        at com.cplatform.config.PropertiesConfig.<init>(PropertiesConfig.java:119)
        at com.cplatform.sms_notice.client.SysConfig.<init>(SysConfig.java:50)
        at com.cplatform.sms_notice.client.SysConfig.init(SysConfig.java:41)
        at com.cplatform.sms_notice.client.MainEntry.main(MainEntry.java:23)

错误很明显了,我们的jar包需要读取目录下面的配置文件,shell脚本的路径没有设置好,就容易出现这样那样的问题,最后修改脚本,

cd usr/local/japp/****

/usr/local/japp/jre16/bin/java -jar ***.jar  &

       再次启动脚本,shell脚本运行正常!

原文地址:https://www.cnblogs.com/lykbk/p/sdsdsdw34werwewerwewewewewe.html