Maven 2 & 3

Cannot build m2 with spaces in M2_HOME and/or JAVA_HOME

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0-alpha-1
  • Fix Version/s: 2.0-alpha-2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows XP, Cygwin.
  • Number of attachments :
    3

Description

There are numerous problems when trying to build m2 in Windows when JAVA_HOME or M2_HOME contains spaces. The attached patch fixes enough of the scripts to build m2 under cygwin, but there still exist several major flaws when using the .bat versions.

To detail the various problems, I shall annotate the patch here:

> Index: m2-bootstrap-all.sh
> ===================================================================
> @@ -1,7 +1,7 @@
> -[ -z $JAVA_HOME ] && echo && echo 'You must set $JAVA_HOME to use mboot!' && echo && exit 1
> +[ -z "$JAVA_HOME" ] && echo && echo 'You must set $JAVA_HOME to use mboot!' && echo && exit 1

Quote for spaces in JAVA_HOME.

> @@ -19,7 +19,11 @@
> - ARGS="$ARGS -Dmaven.home=$M2_HOME"
> + if [ -n "$ARGS" ]; then
> + ARGS="$ARGS -Dmaven.home=$M2_HOME"
> + else
> + ARGS="-Dmaven.home=$M2_HOME"
> + fi

Previously, if no ARGS are supplied then "$ARGS" equates to " -Dmaven.home=$M2_HOME" which is not recognised by javac and a typical -D arg. Basically ARGS cannot start or end with a space when later quoted.

> @@ -39,7 +43,7 @@
> - $JAVACMD $ARGS $MAVEN_OPTS -jar mboot.jar
> + "$JAVACMD" "$ARGS" $MAVEN_OPTS -jar mboot.jar

First quote for spaces in JAVA_HOME, second for spaces in M2_HOME. Not sure if "$ARGS" works for multiple arguments with spaces, i.e. "-Dprop1=C:/Program Files/a -Dprop2=C:/Program Files/b". From previous experience I seem to remember having to quote each -D seperately..

> Index: maven-core/src/bin/m2.bat
> ===================================================================
> @@ -127,7 +127,7 @@
> %MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %M2_HOME%\core\boot\classworlds*.jar "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" org.codehaus.classworlds.Launcher %MAVEN_CMD_LINE_ARGS%
> +%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath "%M2_HOME%\core\boot\classworlds-1.1-alpha-1.jar" "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" org.codehaus.classworlds.Launcher %MAVEN_CMD_LINE_ARGS%

m2.bat gets called eventually via the script even under cygwin, hence this fix. Normal quote for M2_HOME in classpath here, but also the classworlds.jar part does not work under Windows when fully qualified. i.e. Within M2_HOME/core/boot a javac cp classworlds.jar will work, but not once it's fully qualified as it is here. Not an ideal solution as we have to hardcode the classworlds version.

> Index: maven-core/src/bin/m2
> ===================================================================
> @@ -126,7 +126,7 @@
> -exec $JAVACMD \
> +exec "$JAVACMD" \

Quoted for spaces in JAVA_HOME.

> Index: maven-mboot2/build
> ===================================================================
> @@ -9,8 +9,8 @@
> -$JAVA_HOME/bin/javac -g -d ${classesDir} `find ${srcDir} -name '*.java'`
> +"$JAVA_HOME/bin/javac" -g -d ${classesDir} `find ${srcDir} -name '*.java'`

Quoted for spaces in JAVA_HOME.

> -( cd ${classesDir} ; $JAVA_HOME/bin/jar -cfm ../mboot.jar ../../manifest.txt * )
> +( cd ${classesDir} ; "$JAVA_HOME/bin/jar" -cfm ../mboot.jar ../../manifest.txt * )

Quoted for spaces in JAVA_HOME.

> Index: maven-core-it/maven-core-it.sh
> ===================================================================
> @@ -25,9 +25,5 @@
> -if [ ! -z "$M2_HOME" ]; then
> - jvm_args="$jvm_args -Dmaven.home=$M2_HOME"
> -fi

Potentially controversial, but maven-core-it.sh receives -Dmaven.home in it's args from the parent calling script, so applying this again here causes the following args to be used:

-Dmaven.home=C:/Program Files/maven2 -Dmaven.home=C:/Program Files/maven2

Which when quoted, results in maven.home equalling "C:/Program Files/maven2 -Dmaven.home=C:/Program Files/maven2". This is a symptom of quoting multiple args with spaces as described above.

> +java "$jvm_args" -cp "$cp" $verifier
> -java $jvm_args -cp "$cp" $verifier

Quoted for spaces in M2_HOME.

I started to look at fixing the bat files for the pure Windows build, but came across fundamental problems in maven-mboot2/build.bat - the @argfile form of javac only works under Windows if any paths with spaces are quoted within it. So knowing the 'power' of DOS, this didn't seem an easy task.

All of this investigation led me to ask why you guys didn't use Ant instead of native scripts?!

Any feedback would be welcome, cheers.

  1. patch
    08/May/05 10:38 AM
    3 kB
    Mark Hobson
  2. patch2.txt
    09/May/05 5:05 AM
    0.3 kB
    Mark Hobson
  3. patch3.txt
    10/May/05 10:27 AM
    0.4 kB
    Mark Hobson

Activity

Hide
Brett Porter added a comment -

applied with modifications.

  • Made discovering the classworlds JAR in the bat file work.
  • added back maven.home passing in maven-core-it.sh, your change didn't work if jvm_args was non-empty.

"All of this investigation led me to ask why you guys didn't use Ant instead of native scripts?!"

Because the hardest changes were in m2.bat and the m2 shell which we need to work anyway

Ultimately, m2 should build with itself as much as possible.

Show
Brett Porter added a comment - applied with modifications.
  • Made discovering the classworlds JAR in the bat file work.
  • added back maven.home passing in maven-core-it.sh, your change didn't work if jvm_args was non-empty.
"All of this investigation led me to ask why you guys didn't use Ant instead of native scripts?!" Because the hardest changes were in m2.bat and the m2 shell which we need to work anyway Ultimately, m2 should build with itself as much as possible.
Hide
Mark Hobson added a comment -

All works apart from missing quotes in maven-core-it.sh - patch2.txt uploaded.

Show
Mark Hobson added a comment - All works apart from missing quotes in maven-core-it.sh - patch2.txt uploaded.
Hide
Mark Hobson added a comment -

maven-core-it.sh patch

Show
Mark Hobson added a comment - maven-core-it.sh patch
Hide
Brett Porter added a comment -

Mark, when I did this it broke because I had MAVEN_OPTS set to:
-Duser.home=c:/home/brett -Dtestuser.name=maven
resulting in:
java.lang.NoClassDefFoundError: -Duser/home=c:/home/brett -Dtestuser/name=maven

I've instead taken out the additional -Dmaven.home which should get by most issues.

Show
Brett Porter added a comment - Mark, when I did this it broke because I had MAVEN_OPTS set to: -Duser.home=c:/home/brett -Dtestuser.name=maven resulting in: java.lang.NoClassDefFoundError: -Duser/home=c:/home/brett -Dtestuser/name=maven I've instead taken out the additional -Dmaven.home which should get by most issues.
Hide
Mark Hobson added a comment -

The cygpath -p switch was introduced when qualifying M2_HOME under cygwin - this produces an invalid maven.home property when passed into MBoot, e.g.:

[mark@mark components]$ echo $M2_HOME
C:\Program Files\maven-2.0
[mark@mark components]$ cygpath -pw "$M2_HOME"
C;c:\Program Files\maven-2.0

Results in:

Exception in thread "main" java.io.FileNotFoundException: c:\Documents and Settings\mark\My Documents\projects\oss\maven
\components\C;c:\Program Files\maven-2.0\bin\m2 (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at util.FileUtils.copyFile(FileUtils.java:726)
at util.FileUtils.copyFileToDirectory(FileUtils.java:686)
at util.FileUtils.copyFileToDirectory(FileUtils.java:663)
at MBoot.run(MBoot.java:382)
at MBoot.main(MBoot.java:117)

patch3.txt fixes this.

Show
Mark Hobson added a comment - The cygpath -p switch was introduced when qualifying M2_HOME under cygwin - this produces an invalid maven.home property when passed into MBoot, e.g.: [mark@mark components]$ echo $M2_HOME C:\Program Files\maven-2.0 [mark@mark components]$ cygpath -pw "$M2_HOME" C;c:\Program Files\maven-2.0 Results in: Exception in thread "main" java.io.FileNotFoundException: c:\Documents and Settings\mark\My Documents\projects\oss\maven \components\C;c:\Program Files\maven-2.0\bin\m2 (The filename, directory name, or volume label syntax is incorrect) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:179) at java.io.FileOutputStream.<init>(FileOutputStream.java:131) at util.FileUtils.copyFile(FileUtils.java:726) at util.FileUtils.copyFileToDirectory(FileUtils.java:686) at util.FileUtils.copyFileToDirectory(FileUtils.java:663) at MBoot.run(MBoot.java:382) at MBoot.main(MBoot.java:117) patch3.txt fixes this.
Hide
Mark Hobson added a comment -

Reopened to attached patch3.txt.

Show
Mark Hobson added a comment - Reopened to attached patch3.txt.
Hide
Mark Hobson added a comment -

patch3.txt

Show
Mark Hobson added a comment - patch3.txt
Hide
Brett Porter added a comment -

sorry, force of habit

Show
Brett Porter added a comment - sorry, force of habit

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: