2013-07-29 49 views
0

我想從shell腳本調用java jar。它適用於windown批處理腳本。我試圖將這個工作批處理腳本翻譯成一個shell腳本,但是沒有得到它的工作。錯誤在哪裏?從shell腳本中調用java應用程序

原來的批處理文件(完美的作品):

@echo off 
rem set the right host here 
set host=example.com 
set port=8080 
set urlPartBeforeApiVersion=/project/api 
rem geographical region 
set west=47.358352 
set south=8.493598 
set east=47.406704 
set north=8.560889 
set numberOfVehicles=10 
set idPerfix=SIM_KSDN128D 
set vehicleSpeed=40 
set gpsSendInterval=10 
set cloudmadeApiKey=kldhfjsghjf83hf83hf83hf89whs89 
java -jar %~p0dist/application.jar %host% %port% %west% %south% %east% %north% %numberOfVehicles% %idPerfix% %vehicleSpeed% %gpsSendInterval% %urlPartBeforeApiVersion% %cloudmadeApiKey% 
pause 

shell腳本(不工作):

#!/bin/sh 
host="example.com" 
port="8080" 
urlPartBeforeApiVersion="/project/api" 
west="47.358352" 
south="8.493598" 
east="47.406704" 
north="8.560889" 
numberOfVehicles="10" 
idPerfix="SIM_KSDN128D" 
vehicleSpeed="40" 
gpsSendInterval="10" 
cloudmadeApiKey="kldhfjsghjf83hf83hf83hf89whs89" 
java -jar $(dirname $0)/dist/application.jar $host $port $west $south $east $north $numberOfVehicles $idPerfix $vehicleSpeed $gpsSendInterval $urlPartBeforeApiVersion $cloudmadeApiKey 

應用程序會引發一個Java NumberFormatException異常並退出。我在Windows 7和Centos上測試了cygwin上的腳本。

+1

粘貼完整堆棧跟蹤,你傳遞錯誤的應用程序不期望 –

+0

你得到什麼錯誤? – drvdijk

+0

「xception in thread」main「java.lang.NumberFormatException:For input string:」8080 at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java。 lang.Integer.parseInt(Unknown Source) at application.Application.main(Application.java:36) –

回答

1

這是當你的bash腳本有DOS行分隔符時可能發生的許多奇妙事情之一。

通過dos2unixsed -i 's/\r//',tr -d '\r'或任何你有的東西運行你的腳本,然後重試。

以供將來參考,當你看到一個符合垃圾開始,是偷偷摸摸地截斷,如

"xception [...]: For input string: "8080 

而不是

Exception [...]: For input string: "8080" 

你知道你正在處理回車。

+0

這個問題解決了,非常感謝! –

相關問題