开发者

Why does my program work in eclipse, but generates a "filename, directory name, or volume label syntax is incorrect" error when jarred with maven?

I have a class (called LogCopy) I've written which when I run it in Eclipse with the 4 parameters it's supposed to have, in the correct format, surprise, surprise, runs perfectly fine. The trouble is, I need to .jar it up to put onto a live system & that's where it gets squirly. The parameters are 2 datetime stamps & 2 filenames. It's being developed & executed on a Windows system so the parameters I've supplied to test with are:

2011-03-20|10:21:20 2011-03-20|10:21:21 F:\somepath\logfile.txt F:\somepath\logfileoutput.txt

Now, putting those into a Run Configuration in Eclipse gets the desired response. If I remove a parameter or put in a value that isn't a valid date or a readable input file or a locked output file, it throws exceptions as I've set it up to do, all well & good. But when I jar it up using maven, and run it with the 4 parms as they're supposed to be I get the cryptic

The filename, directory name, or volume label syntax is incorrect

Strangely though I still get the expe开发者_JS百科cted error messages when I deliberately mess up the parameters, so

java -jar LogCopy-0.0.1-SNAPSHOT-jar-with-dependencies.jar parm1 parm2 parm3 parm4 

gets an error log entry for each thing that's wrong about the parameters - that the dates aren't valid dates, the filenames aren't referring to files that can be used, and a little precis of the command's syntax so the user can correct what they've entered.

How come the valid filenames are giving this weird error message? I've tried entering the filenames in various formats, using forward slashes, backslashes, escaped backslashes, all sorts, but they all give the same (non programmed by me) error message. What gives?


I sussed it - & you're all going to think I've been a total noob about this & you'd be right. One of those "D'OH!!" moments. Turns out the parms only work properly if passed in as strings in double quotes, so:

java -jar LogCopy.jar "2011-05-04|10:05:23" "2011-05-04|10:05:26" "C:\dir\fromfile.txt" "C:\dir2\tofile.txt"

works, while without the double quotes Java mis-parses the parameters & appears to take part of the date as a filename.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜