Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven ${user.home} not being resolved correctly

I've got the following line in my pom.xml:

<updateRepositoryURL>file:/${user.home}/.m2/repository/repository.xml</updateRepositoryURL>

and when I am attempting to use it within my program the resultant string is:

file:/c:Documents and Settings<myusername>/.m2/repository/repository.xml

where <myusername> is my user name funnily enough.

however it should be

file:/c:/Documents and Settings/<myusername>/.m2/repository/repository.xml

Does anyone out there have any ideas as to why it is not resolving properly?

Thanks in advance

like image 780
schubySteve Avatar asked Mar 01 '23 05:03

schubySteve


1 Answers

This might be a bug in maven. I've bookmarked this workaround some time ago:

I found a handy way to reference the Java system property ${user.home} within a Maven build that supports Windows' ridiculous path name to home/profile directories:

c:\Documents and Settings\foobar.

The problem is, when using Maven, this parameterized property doesn't get passed through as one property value, but as three, because somewhere in the build Maven chokes on the spaces or back-slashes and interprets it as either three arguments:

"c:\Documents", "and", "Settings\foobar"

or treats the windows back-slash as an escape character and removes them so my parameterized user.home becomes:

"c:Documents and Settingsfoobar"

[...]

However, on Windows XP, unless I set the user.home on the build path every time, the back-slash escaping or space issues cause the files to not be found.

To fix it, add this profile to the $M2_HOME/conf/settings.xml file:

<profile>
<id>laptop-xp</id>
<properties>
<user.home>C:/Documents and Settings/${user.name}</user.home>
</properties>
</profile>

Then add an appropriate entry to the activeProfiles:

<activeProfile>laptop-xp</activeProfile>

Now every user will be able to use the user.home property to reference their home path correctly on the Windows box.

Or, you're just another victim of this bug: http://bugs.sun.com/view_bug.do?bug_id=4787931. It's a very old bug (more than 6 years old) that affects all versions up till Java 1.6.x.

like image 57
Pascal Thivent Avatar answered Mar 07 '23 11:03

Pascal Thivent