• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jar problem : arguments with spaces

 
Darren Wilkinson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All :-)

I am trying to get my program to run from the command line and something about the csvDirectoryPath part is tripping up my program. This all works fine when run from within Netbeans with these arguments but not from the command line.

I have searched and searched for how to add arguments - use spaces - but can't find anything relating to 'wrapping' arguments that contain spaces.

Can anyone help - thank you

Command Line

C:\Documents and Settings\Simon\Desktop\dist\dist>java -jar "Mobileseeker_Feed_Manager.jar" "command=loadActiveFeed" "totalLines=all" "csvDirectoryPath=C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16\work\Catalina\localhost\mobileDataFeeds\091008\" "feedsTable=tbl_feeds"

Program output

Processing Feed Data start...
Getting process commands...
command=loadActiveFeed
totalLines=all
csvDirectoryPath=C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16\work\Catalina\localhost\mobileDataFeeds\091008" feedsTable=tbl_feeds

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 at org.mobileseeker.command.MobileseekerClient.main(MobileseekerClient.java:42)
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting the quotes around just the value
i.e. change
"csvDirectoryPath=C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16\work\Catalina\localhost\mobileDataFeeds\091008\"
to
csvDirectoryPath="C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16\work\Catalina\localhost\mobileDataFeeds\091008\"

I don't think you need to put any quotes around arguments that don't contain spaces (although it probably doesn't matter if you do)
i.e.
"command=loadActiveFeed"
can probably also be written as
command=loadActiveFeed
[ October 14, 2008: Message edited by: Joanne Neal ]
 
Darren Wilkinson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joanne,

I tried your suggestion but same error message I'm afraid :-(
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the array you are putting the arguments into is large enough ? The error appears to happen when you process the feedsTable argument. You are trying to put it into the fourth element of a array of size 3.
 
Bert Deville
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also think the array size is calling the problem, not the csvDirectoryPath.

public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsExceptionThrown
to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array."
[ October 14, 2008: Message edited by: Bert Deville ]
 
Darren Wilkinson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The array is the main methods arguments String[] array.

The arguments passed into a jar via the command line seem to be seperated by spaces. The csvDirectoryPath argument has spaces - even when surrounded by quotes. So I'm not sure how to 'wrap' an argument that contains spaces.

This all works fine when run from within Netbeans with these arguments but not from the command line.

Within the main method:



[ October 14, 2008: Message edited by: Darren Wilkinson ]
[ October 14, 2008: Message edited by: Darren Wilkinson ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to read 5 arguments from the command line but your example in the original post only passes four.
 
Darren Wilkinson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Joanne, thanks for that spot. I also noticed it and ran with the correct number of arguments but... you guessed it... same error :-(

Have you noticed in the error,the end of the path has a single " as if the string is incorrectly parsed - this is what makes me think it is the spaces in the path... but then, what do I know lol
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should do a flag-parsing-method. Now you are relying on the correct order of the arguments. If the user would change the order (and they will), then everything would break down.
 
Darren Wilkinson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fair point Ove.

Some background explains this. The program is a quick and dirty test to automate our feed processing code. It is called automatically from a script that supplies the argument values - so I agree, ideally that needs to change but for now its ok.

The big problem is why the path blows on the command line but is fine in netbeans
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic