0

I'm trying to invoke a java jar from a shell script. It works with a windown batch script. I tried to translate this working batch script into a shell script but don't get it working. Where is the bug?

The original batch file (works perfectly):

@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

The shell script (doesn't work):

#!/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

The application throws a Java NumberFormatException and exits. I tested the script on cygwin on Windows 7 and on centos.

7
  • 1
    paste full stacktrace, you are passing something wrong that app isn't expecting Commented Jul 29, 2013 at 16:30
  • what's the error you're getting? Commented Jul 29, 2013 at 16:30
  • "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) Commented Jul 29, 2013 at 16:34
  • Is the value you are that you parsing to int represented by one of the parameters you're passing at the command line? Commented Jul 29, 2013 at 16:37
  • 1
    Can you change #!/bin/sh to #/bin/bash and retry? Also, try putting echo before java temporarily to see what's being actually passed? Commented Jul 29, 2013 at 16:55

1 Answer 1

1

This is one of the many wonderful things that can happen when your bash script has DOS line separators.

Run your script through dos2unix, sed -i 's/\r//', tr -d '\r' or whatever you have available, and try again.

For future reference, whenever you see that a line starts with garbage and is surreptitiously truncated, such as

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

rather than

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

You know that you're dealing with carriage returns.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.