执行jar文件的Bash脚本返回无法访问ssh中的jarfile app.jar

时间:2016-09-30 09:54:28

标签: java bash ssh jar

我有bash脚本 run.sh 执行 jar 文件:

import UIKit

let button = UIButton(frame: CGRect(x: 0, y: 0, width: 300, height: 30))
button.setTitle("Order", for: .normal)
button.backgroundColor = UIColor.darkGray

let gradientLayer = CAGradientLayer()
gradientLayer.frame = button.bounds
gradientLayer.startPoint = CGPoint(x: 0, y: 0.5) //Set the start point to the left edge center
gradientLayer.endPoint = CGPoint(x: 1, y: 0.5) //Set end point to the right edge center
gradientLayer.colors = [UIColor.clear.cgColor, UIColor.red.withAlphaComponent(0.5).cgColor, UIColor.red.withAlphaComponent(0.5).cgColor, UIColor.clear.cgColor]
gradientLayer.locations = [0, 0.2, 0.8, 1] //At the start point, the clear color is used; at 20% horizontal, red is used, etc

button.layer.insertSublayer(gradientLayer, at: 0)
button

当我在服务器上执行它时,它会起作用

但是,当我尝试使用 ssh

执行它时
#!/bin/bash

APPNAME=app
JARFILE=app.jar
JAVA_OPTS="-DTitle=$APPNAME -Xmx256m"
ARGS=test

echo "Starting $APPNAME with $ARGS..."
java $JAVA_OPTS -jar $JARFILE $ARGS

它返回错误:

ssh host '/path-to-bash-script/run.sh'

请注意,服务器是64位Ubuntu

1 个答案:

答案 0 :(得分:0)

对我有用的一个解决方案是将当前目录更改为脚本所在的目录,即:

SCRIPTPATH=`dirname $0`
cd $SCRIPTPATH

应放在

之前

java $JAVA_OPTS -jar $JARFILE $ARGS