This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 237398 - Failed to run maven with custom installation with 7.4
Summary: Failed to run maven with custom installation with 7.4
Status: VERIFIED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Milos Kleint
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-21 08:05 UTC by moghrabi
Modified: 2013-11-22 14:28 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
maven output (45.68 KB, text/plain)
2013-10-21 08:05 UTC, moghrabi
Details
Custom mvn.bat (6.24 KB, application/octet-stream)
2013-10-21 09:45 UTC, moghrabi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description moghrabi 2013-10-21 08:05:40 UTC
Created attachment 141329 [details]
maven output

Hi,

I have a custom installation of Maven (3.0.5) provided by my enterprise on Windows 7 64 bits.

The installation used to work well with Netbeans 7.3 but it fails with 7.4.

Find in attachment the log when I run a clean install with Netbeans 7.4.

The issue comes from the fact that our maven command use to add other options at the end of the line and Netbeans 7.4 surrounds the command line by double quotes :
cmd /c "\"\"E:\\projects\\maven\\mvn3\\bin\\mvn.bat\" -Dmaven.ext.class.path=E:\\projects\\netbeans\\7.4\\java\\maven-nblib\\netbeans-eventspy.jar clean install\"\""

Thus the command line generated by ou custom maven is :
"E:\projects\jboss\jdk\64\1.6.0_31\bin\java.exe"  -Dproject.license=LO -classpath "E:\projects\maven\mvn3\bin\..\boot\plexus-classworlds-2.4.jar" "-Dclassworlds.conf=E:\projects\maven\mvn3\bin\..\bin\m2.conf" "-Dmaven.home=E:\projects\maven\mvn3\bin\.." org.codehaus.plexus.classworlds.launcher.Launcher -Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-eventspy.jar clean install" -Dhttp.nonProxyHosts=maven  -Pjrebel

With the previous version 7.3 it was the command line was not surrounded by double quotes.

I don't think there is a need to surround the whole command line with double quotes : an alternative could be to surround only path that may contain white space :
cmd /c "\"E:\\projects\\maven\\mvn3\\bin\\mvn.bat\" \"-Dmaven.ext.class.path=E:\\projects\\netbeans\\7.4\\java\\maven-nblib\\netbeans-eventspy.jar\" clean install"

Best regards.
Comment 1 Milos Kleint 2013-10-21 08:18:22 UTC
your maven installation is doing non-standard things in mvn.bat? isn't MAVEN_OPTS supposed to do that? or .m2/settings.xml?

The reason why we now run cmd /c on windows is that since 1.7_u21, the execution we used to have before is no longer executing in java and an error is thrown.

see issue 228901
Comment 2 moghrabi 2013-10-21 09:02:24 UTC
I've ran the script with @echo on and add debug option.

First the command line receive by the script is (%CmdCmdLine%) :
"cmd" /c ""E:\projects\maven\mvn3\bin\mvn.bat" -Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-eventspy.jar clean install""

First it seems to have an extra double quote.

Then when the script takes the parameters with %* it gets :
 -Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-eventspy.jar clean install"


I think a double quote is missing before the -Dmaven.ext.class.path option, don't you ?
Comment 3 Milos Kleint 2013-10-21 09:16:34 UTC
(In reply to moghrabi from comment #2)
> I've ran the script with @echo on and add debug option.
> 
> First the command line receive by the script is (%CmdCmdLine%) :
> "cmd" /c ""E:\projects\maven\mvn3\bin\mvn.bat"
> -Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-
> eventspy.jar clean install""
> 
> First it seems to have an extra double quote.
> 
> Then when the script takes the parameters with %* it gets :
>  -Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-
> eventspy.jar clean install"
> 
> 
> I think a double quote is missing before the -Dmaven.ext.class.path option,
> don't you ?

each of the parameters needs to be quoted separately if it contains a space. eg.
-Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-eventspy.jar doesn't need quoting but -Dmaven.ext.class.path=E:\projects\netbeans 7.4\java\maven-nblib\netbeans-eventspy.jar would.. Same with any other -D parameter passed in.
So quoting all parameters makes no sense, there's no way to figure out where the space means "new parameter" and when it's just part of the parameter's value.
Comment 4 moghrabi 2013-10-21 09:30:43 UTC
I don't want you to quote each parameter.

I'd like just to inform you that the command line caught by the %CmdCmdLine% variable contains an extra quote :
"cmd" /c ""E:\projects\maven\mvn3\bin\mvn.bat" -Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-eventspy.jar clean install""

If you count the quotes there are 7 quotes and the number must be even.
Comment 5 Milos Kleint 2013-10-21 09:38:24 UTC
(In reply to moghrabi from comment #4)
> I don't want you to quote each parameter.
> 

unfortunately that's something I have to do.


> I'd like just to inform you that the command line caught by the %CmdCmdLine%
> variable contains an extra quote :
> "cmd" /c ""E:\projects\maven\mvn3\bin\mvn.bat"


The command line has to start with doubled quotes and end with doubled quotes. Then if the bat file path contains space, it has to be quoted as well, I recall that doing """E:\projets with space\mvn.bat" didn't however work and for some reason ""E:\projets with space\mvn.bat" did.


> -Dmaven.ext.class.path=E:\projects\netbeans\7.4\java\maven-nblib\netbeans-
> eventspy.jar clean install""
> 
> If you count the quotes there are 7 quotes and the number must be even.

I'm not claiming the way it works now is perfect or correct, however it did work for the tested scenarios with maven and/or netbeans in path with spaces and parameters with spaces etc. 
Can you attach your changes done to the mvn.bat file? 
Once I'm on windows, I'll take a look.
Comment 6 moghrabi 2013-10-21 09:45:53 UTC
Created attachment 141338 [details]
Custom mvn.bat
Comment 7 moghrabi 2013-10-21 09:49:44 UTC
Regarding the cumstom mvn.bat :

Line 37, added :
setlocal

Line 42, replace :
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
by :
set HOME=%~dp0
REM OLD WAY: => if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
if "%JDK_SET%" == "" SET JAVA_HOME=%HOME%..\jdk\32bits\jdk150_12
if not "%FORGE_HOME%"=="" set JAVA_HOME=E:\projects\jboss\jdk\64\1.6.0_31

Line 124, replace :
set MAVEN_CMD_LINE_ARGS=%*
by :
set MAVEN_CMD_LINE_ARGS=%* %CUSTOM_CMD_LINE_ARGS%

The variable CUSTOM_CMD_LINE_ARGS is initialized in mavenrc_pre.bat with :
-Dhttp.nonProxyHosts=maven -Pjrebel
Comment 8 Milos Kleint 2013-10-22 11:20:42 UTC
http://hg.netbeans.org/core-main/rev/affb5363a53a
http://hg.netbeans.org/core-main/rev/125df70956a2

these 2 changeset should fix the problem for you (the dev build where the fix is included will appear as comment later on). Indeed it's possible to remove the second double quote, I was not able to find a scenario where it would fail, with the exception of some old code that was obsolete anyway. Please test with your scenario. I've only turned MAVEN_BATCH_ECHO on to see what is being passed to java executable.
Comment 9 Quality Engineering 2013-10-23 02:06:25 UTC
Integrated into 'main-silver', will be available in build *201310230001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/affb5363a53a
User: Milos Kleint <mkleint@netbeans.org>
Log: #237398 apparently a single doublequote is enough here
Comment 10 moghrabi 2013-10-23 13:49:59 UTC
I've just tested the nightly build with my custom installation of Maven.

I can confirm you that the patch works fine for me.

Thank you for the correction.
Comment 11 Tomas Danek 2013-11-04 12:40:23 UTC
-> marking Verified.
(In reply to moghrabi from comment #10)
> I've just tested the nightly build with my custom installation of Maven.
> 
> I can confirm you that the patch works fine for me.
> 
> Thank you for the correction.
Comment 12 Milos Kleint 2013-11-13 09:50:45 UTC
http://hg.netbeans.org/releases/rev/ba5264927b74
Comment 13 Quality Engineering 2013-11-14 14:32:19 UTC
Integrated into 'releases/release74', will be available in build *201311141216* or newer. Wait for official and publicly available build.

Changeset: http://hg.netbeans.org/releases/rev/ba5264927b74
User: Milos Kleint <mkleint@netbeans.org>
Log: #237398 apparently a single doublequote is enough here
Comment 14 Tomas Danek 2013-11-22 14:28:51 UTC
changeset http://hg.netbeans.org/core-main/rev/125df70956a2 is not in release, however passed for me in 7.4 patch 1, when appended two properties to line:
set MAVEN_CMD_LINE_ARGS=%*
mvn run passed and echo showed props passed correctly.