File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes jar problem : arguments with spaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "jar problem : arguments with spaces" Watch "jar problem : arguments with spaces" New topic
Author

jar problem : arguments with spaces

Darren Wilkinson
Ranch Hand

Joined: May 22, 2007
Posts: 35
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

Joined: Aug 05, 2005
Posts: 3446
    
  12
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 ]

Joanne
Darren Wilkinson
Ranch Hand

Joined: May 22, 2007
Posts: 35
Thanks Joanne,

I tried your suggestion but same error message I'm afraid :-(
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3446
    
  12
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

Joined: Oct 10, 2008
Posts: 8
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

Joined: May 22, 2007
Posts: 35
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

Joined: Aug 05, 2005
Posts: 3446
    
  12
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

Joined: May 22, 2007
Posts: 35
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

Joined: Mar 10, 2008
Posts: 326

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

Joined: May 22, 2007
Posts: 35
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jar problem : arguments with spaces