jMoby is a Java project and Java is Operating System independent. So what is the point to raise issues about MS-Windows?

Well, because the life is not always easy...

The good news is that most issues listed in this document are already solved in jMoby, and they are here just to remember them, and to advise how to go around them.

Microsoft surprises... and how to deal with them

Just a note: I am not a Windows developer. I found these issues when working with jMoby - that functioned fine under Linux - on Windows. And I had to solve them at once. So perhaps I have not found an optimal solution. That's why I will be glad to update this document with new views.

Empty command-line arguments

The command-line parameters for Windows scripts - when the line is built by Ant - cannot remain empty. If they do, they simply disappear. This is an example of a script/program invoked from Ant:
<java classname="MosesGenerators" taskname="Service(s)"
  classpathref="" fork="true" failonerror="true">
  <arg value="-e"/>
  <arg value="${default.endpoint}"/>
  <arg value="-uri"/>
  <arg value="${default.namespace}"/>
When the property ${default.endpoint} is not defined, Ant will use a default value, which is an empty string, defined in the same Ant as:
<property name="default.endpoint" value=""/>
This works fine under Linux: the invoked program gets four arguments (I have labeled them by numbers, and put them in single quotes - but neither numbers nor quotes are parts of the arguments):
(1) '-e'
(2) ''
(3) -uri
(4) ''
Unfortunately, under Windows the arguments (2) and (4) disappear, and the invoked program gets this:
(1) '-e'
(2) -uri
I asked Ant forum why it is like that - and the answer was simply "this is how Windows command processor does it". Which is fine with me - if Ant - which claims to hide platform dependencies - solves it. But it does not.

Therefore, in jMoby, I have introduced a new convention (which I had to teach my programs): when an argument contains only two double quotes it is considered empty. So, now, in Ant, an empty default value is defined like this:

<property name="default.endpoint" value="&quot;&quot;"/>
<property name="default.namespace" value="&quot;&quot;"/>
On Windows, it produces correctly empty arguments:
(1) '-e'
(2) ''
(3) -uri
(4) ''
On Linux, my programs need to understand arguments like this:
(1) '-e'
(2) '""'
(3) -uri
(4) '""'
It was easy to fix, because all jMoby command-line programs uses a simple command-line reader (a utility class) which I updated to replace two double quotes by an empty string. But keep this in mind if your programs uses a different command-line reader (such as Apache CLI).

Too many command-line parameters

Update (November 2005):
I found that Windows actually understand a similar construct as UNIX does: %* which is substituted with all arguments from the command line:
@echo off
java Program %*
Therefore, this section would not be needed. But, as stated below, to have a way how to use often used subset of command-line arguments from a file is useful on its own, so I keep this section here.

End of Update

I still know only how to pass maximum nine parameters to a Windows batch script (does anybody knows how to pass more?):

@echo off
java Program %1 %2 %3 %4 %5 %6 %7 %8 %9
And it is not enough for some jMoby scripts (e.g. run-service.bat). That's why I added also another feature to the (already mentioned above) command-line reader it can accept a special command line parameter:
-argsfile <filename>
This can include as many as needed arguments - each one on a separate line. The details are taken from src/Clients/help/argsfile.example file:
# All clients that use '' class for
# accessing command-line arguments can also read all or some arguments
# from a file. The file name is given as -argsfile parameter. There
# may be more than one of them. The arguments read from these files
# are included in the place where the the -argsfile were found.
# The file format of such file is:
#   * Blank lines and lines started by # are ignored.
#   * Each argument and its (possible) value are on a separate line.
#   * Each line will be first trimmed of whitespaces.
#   * Then each line will be trimmed of quotes, if it starts and
#     ends with the same kind of quotes.
# Here is an example:
-next one will be empty
-next one also
Actually, this proved to be handy as a feature on its own: you can store some repeatedly used arguments to a file, and add some in the runtime directly on the command-line.

An equal sign in command-line parameters

If an argument contains an equal sign, it must be double quoted. For example:
build/run/run-service "language=english,czech"
Otherwise Windows splits in into two arguments. The only solution for that is to pay attention to it when you have such arguments (an example where such arguments are used is again the script run-service.bat - see details in the Moses project about the BaseCmdLineClient.

Whitespaces in project directory name

I have not solved this - I only introduced a workaround.

If a directory with jMoby has whitespaces in its name (which is quite common - because the user home directories are by default in C:\Documents And Settings) then some jMoby scripts failed to work. Without going to boring details: a workaround was to add to scripts (to their Windows version) to change first to the project home (this could be achieved even with whitespaces by double quoting name), and then to use relative paths (which, in jMoby, have never any whitespaces).

This is not an ideal solution because (again, only in Windows) such change of directory is kept even after the script finishes. but that's all I could find...

Good luck.

Martin Senger
Last modified: Sun Nov 20 20:05:06 2005