简体   繁体   English

(Mac)从另一个Shell脚本调用Shell脚本在运行Java时给出访问错误

[英](Mac) Calling a shell script from another shell script is giving an access error when running java

I am a front-end dev working on a project for a client. 我是从事客户项目的前端开发人员。 Our back-end team has provided me with several java scripts that must be run which provide data to the application. 我们的后端团队为我提供了一些必须运行的Java脚本,这些脚本向应用程序提供了数据。 All of these scripts are run from the command line. 所有这些脚本都是从命令行运行的。

What we've been asked to do is to open several instances of Terminal (or several tabs is fine too) and run one script (which calls the java app) per terminal window. 我们被要求做的是打开多个Terminal实例(或几个选项卡也可以),并在每个Terminal窗口运行一个脚本(称为Java应用)。

Right now, doing that involves opening all the windows by hand, using "cd" commands to get to the correct folder(s), and then running the java command, all by hand. 现在,要做的事情包括手动打开所有窗口,使用“ cd”命令进入正确的文件夹,然后手动运行java命令。 I'd like to automate this process. 我想自动化这个过程。

First, I wrote a shell script (launch_language) to call the java file in the correct folder. 首先,我编写了一个Shell脚本(launch_language)来调用正确文件夹中的Java文件。 Running this command by itself works just fine, and runs the program as expected : 单独运行此命令可以正常运行,并按预期运行程序

#!/bin/bash
java -jar mercury/language-packs/language-connector/target/language-connector-1.12.7.jar

So far, so good. 到现在为止还挺好。

Now, I want to write another script, which will open a new Terminal window, then load and run this working script. 现在,我想编写另一个脚本,它将打开一个新的“终端”窗口,然后加载并运行此工作脚本。 Okay, so: 可以,然后呢:

#!/bin/bash
open -a Terminal.app launch_language

Running this script opens a new terminal window as expected, and launches the launch_language script. 运行此脚本将按预期打开一个新的终端窗口,并启动launch_language脚本。 When that happens however, the Terminal gives me this error: 但是,如果发生这种情况,终端会给我这个错误:

Error: Unable to access jarfile mercury/language-packs/language-connector/target/language-connector-1.12.7.jar

Any thoughts as to why calling the launch_language script this way is causing this error to occur? 关于为什么以这种方式调用launch_language脚本导致此错误发生的任何想法?

You are using relative path in your script - so it works only if you run it from specific directory. 您正在脚本中使用相对路径-因此,仅当从特定目录运行它时,它才起作用。

Possible solutions: 可能的解决方案:

  1. add cd /FULL_PATH_TO_DIR before java -jar command java -jar命令之前添加cd /FULL_PATH_TO_DIR
  2. provide full path to jar ( /FULL_PATH_TO_DIR/mercury/language-packs/language-connector/target/language-connector-1.12.7.jar ) 提供jar的完整路径( /FULL_PATH_TO_DIR/mercury/language-packs/language-connector/target/language-connector-1.12.7.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM