You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jimisola Laursen <li...@jimisola.com> on 2006/08/24 23:48:37 UTC

Using Java System Properties in pom.xml

Hi!

Been reading through the documentation on maven.apache.org and the book, but
I can't find any information on if it is possible to use Java System
Properties such as file.separator, user.name and more
(http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties())
in pom.xml?

I have a problem with file separators because we use both Linux and Windows
when developing and it therefore looks as I if I need to use
${file.separator} in our common POM.

Regards,
Jimisola
-- 
View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5973537
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Eric Redmond <er...@gmail.com>.
On 8/27/06, Jimisola Laursen <li...@jimisola.com> wrote:
>
>
> >> I was started to assume that there was a bug in Maven while in fact the
> >> JRE was a fault. Seems kind of odd that it doesn't work both ways. One
> >> would
> >> think that Sun would have taken care of that. Anyway, problem solved.
>
> > Yeah, thats why I said "you can just use *forward slash* for paths."
> > Backslashes are not platform neutral in Java.
>
> It was not obvious that it was a "just" as in "must" :)


Touché ;)


> Now, we know.
>
> Regards,
> Jimisola
>
>
> --
> View this message in context:
> http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a6013188
> Sent from the Maven - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Eric Redmond
http://codehaus.org/~eredmond

Re: Using Java System Properties in pom.xml

Posted by Jimisola Laursen <li...@jimisola.com>.
>> I was started to assume that there was a bug in Maven while in fact the
>> JRE was a fault. Seems kind of odd that it doesn't work both ways. One
>> would
>> think that Sun would have taken care of that. Anyway, problem solved.

> Yeah, thats why I said "you can just use *forward slash* for paths."
> Backslashes are not platform neutral in Java.

It was not obvious that it was a "just" as in "must" :)

Now, we know.

Regards,
Jimisola


-- 
View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a6013188
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Eric Redmond <er...@gmail.com>.
On 8/27/06, Jimisola Laursen <li...@jimisola.com> wrote:
>
>
> Nick Veys wrote:
>
> > I was under the impression / would _always_ work, on either platform
> when
> > passing a path to the File class.
>
> Me too. That's why I tested on Linux with backslashes in the path..
>
> > So as you can see, the File class is tolerant of windows, but the /
> > path separator works in both cases.  I would just stick with that.  I
> > don't really know exactly what issue this was causing you, unless it
> > was just confusion on the Windows-user side.  Actual manipulation of
> > the file should always work if you use / separators in relative paths.
>
> I was started to assume that there was a bug in Maven while in fact the
> JRE
> was a fault. Seems kind of odd that it doesn't work both ways. One would
> think that Sun would have taken care of that. Anyway, problem solved.


Yeah, thats why I said "you can just use *forward slash* for paths."
Backslashes are not platform neutral in Java.

Thank you for your little test.
>
> Regards,
> Jimisola
> --
> View this message in context:
> http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a6011493
> Sent from the Maven - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
-- 
Eric Redmond
http://codehaus.org/~eredmond

Re: Using Java System Properties in pom.xml

Posted by Jimisola Laursen <li...@jimisola.com>.
Nick Veys wrote:

> I was under the impression / would _always_ work, on either platform when
> passing a path to the File class.

Me too. That's why I tested on Linux with backslashes in the path..

> So as you can see, the File class is tolerant of windows, but the /
> path separator works in both cases.  I would just stick with that.  I
> don't really know exactly what issue this was causing you, unless it
> was just confusion on the Windows-user side.  Actual manipulation of
> the file should always work if you use / separators in relative paths.

I was started to assume that there was a bug in Maven while in fact the JRE
was a fault. Seems kind of odd that it doesn't work both ways. One would
think that Sun would have taken care of that. Anyway, problem solved.

Thank you for your little test.

Regards,
Jimisola
-- 
View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a6011493
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Nick Veys <ps...@gmail.com>.
I was under the impression / would _always_ work, on either platform
when passing a path to the File class.

The String version is definitely not going to do much for you, it
doesn't know it's supposed to be a path.

Here's a quick test I whipped up, outputting whether a file exists
given a relative path to it with both Windows and Linux path
separators on both platforms:

----Test.java------------------
import java.io.File;

public class Test {

    public static void main(String[] args) {
        System.out.println("args[0]: " + args[0]);

        File f = new File(args[0]);
        System.out.println(f.getAbsolutePath() + " exists? " + f.exists());
    }
}

-----------------------------

Running this on my main machine (linux):

nick@sh ~ $ java Test Desktop\\Movies
args[0]: Desktop\Movies
/home/nick/Desktop\Movies exists? false
nick@sh ~ $ java Test "Desktop/Movies"
args[0]: Desktop/Movies
/home/nick/Desktop/Movies exists? true

-----------------------------

Running this on my windows VM:

C:\DOCUME~1\nick>java Test Desktop/test
args[0]: Desktop/test
C:\DOCUME~1\nick\Desktop\test exists? true

C:\DOCUME~1\nick>java Test Desktop\test
args[0]: Desktop\test
C:\DOCUME~1\nick\Desktop\test exists? true

-----------------------------

So as you can see, the File class is tolerant of windows, but the /
path separator works in both cases.  I would just stick with that.  I
don't really know exactly what issue this was causing you, unless it
was just confusion on the Windows-user side.  Actual manipulation of
the file should always work if you use / separators in relative paths.

On 8/27/06, Jimisola Laursen <li...@jimisola.com> wrote:
>
> I've changed the parameter from String to File, but the problem still exist.
>
> I thought at first that it had something to do with the File parameter
> residing in a bean,
> so I tried with both File (fileFile) and String (stringFile) directly.
>
> Using Linux so paths should have slashes /.
>
>
>
> bean (backslash \ exists after target):
> [DEBUG]   (s) outputFile =
> /home/jimisola/p4clients/lt/iso/main/product/common/target\generated-resources/buildinfo-java-common-1.4.0.0-SNAPSHOT.properties
>
> File (<fileFile>slash/backslash\</fileFile>)
>
> [DEBUG]   (f) fileFile =
> /home/jimisola/p4clients/lt/iso/main/product/common/slash/backslash\
>
> String (<stringFile>slash/backslash\</stringFile>):
> [DEBUG]   (f) stringFile = slash/backslash\
>
>
> Using File obviously replaced input (slash/backslash\) with the absolute
> path, but backslashes are not replaced.
>
> Am I missing out on something?  Should this be handled by Maven and
> dependency injection mechanism (Plexus)?
>
> Regards,
> Jimisola
> --
> View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a6010105
> Sent from the Maven - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Jimisola Laursen <li...@jimisola.com>.
I've changed the parameter from String to File, but the problem still exist.

I thought at first that it had something to do with the File parameter
residing in a bean,
so I tried with both File (fileFile) and String (stringFile) directly.

Using Linux so paths should have slashes /.



bean (backslash \ exists after target):
[DEBUG]   (s) outputFile =
/home/jimisola/p4clients/lt/iso/main/product/common/target\generated-resources/buildinfo-java-common-1.4.0.0-SNAPSHOT.properties

File (<fileFile>slash/backslash\</fileFile>)

[DEBUG]   (f) fileFile =
/home/jimisola/p4clients/lt/iso/main/product/common/slash/backslash\

String (<stringFile>slash/backslash\</stringFile>):
[DEBUG]   (f) stringFile = slash/backslash\


Using File obviously replaced input (slash/backslash\) with the absolute
path, but backslashes are not replaced.

Am I missing out on something?  Should this be handled by Maven and
dependency injection mechanism (Plexus)?

Regards,
Jimisola
-- 
View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a6010105
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Jimisola Laursen <li...@jimisola.com>.
Hi,

It's a String:

    /**
     * @parameter   expression="${outputFile}"
     */
    String outputFile;

I'll change it to File and see if that does the works..

Thank you for your information.

This might be something for "the FAQ" or Wiki?

Regards,
Jimisola

Nick Veys wrote:
> 
> Jimisola:
> 
> The parameter that is getting its slashes altered, is it a String or
> File in the the Mojo?  If it is just a String, try a File, I've seen
> your problem before and I believe that handled it.
> 
> On 8/25/06, Jimisola Laursen <li...@jimisola.com> wrote:
>>
>> Hi!
>>
>> Are we taking about the same thing? I am taking about Java System
>> Properties
>> and not System Properties. It was not replaced when I first tried
>> (perhaps I
>> was doing something wrong). the documentation only mentions Java System
>> Properties with filtering.
>>
>> Does the Java System Properties have a prefix or can I just use
>> ${file.separator} in the configuration section?
>>
>> I thought I could use forward slashes for paths too, but the problem is
>> caused with a "home-made" plugin. The plugin takes the output file as a
>> parameter in the configuration section and I don't believe that slashes
>> (/)
>> are replaced with backslashes (\) on the fly. Should I handle this in my
>> plugin perhaps?
>>
>> Sorry if I am missing out on something trivial here. I don't even run
>> Windows myself, so I haven't tested - all I got was a bug report from a
>> team
>> member:
>>
>> Example:
>> ${project.build.directory}/generated-resources/buildinfo-maven-${project.build.finalName}.xml
>>
>> This results in:
>> C:\myrepository\.../generated-resources/buildinfo-maven-....
>>
>> Regards,
>> Jimisola
>>
>>
>> Eric Redmond wrote:
>> >
>> > You can use System properties. However, you don't need to use
>> > file.seperator... you can just use forward slash for paths.
>> >
>> > Eric
>> >
>> > On 8/24/06, Jimisola Laursen <li...@jimisola.com> wrote:
>> >>
>> >>
>> >> Hi!
>> >>
>> >> Been reading through the documentation on maven.apache.org and the
>> book,
>> >> but
>> >> I can't find any information on if it is possible to use Java System
>> >> Properties such as file.separator, user.name and more
>> >> (
>> >>
>> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties()
>> >> )
>> >> in pom.xml?
>> >>
>> >> I have a problem with file separators because we use both Linux and
>> >> Windows
>> >> when developing and it therefore looks as I if I need to use
>> >> ${file.separator} in our common POM.
>> >>
>> >> Regards,
>> >> Jimisola
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5973537
>> >> Sent from the Maven - Users forum at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> >> For additional commands, e-mail: users-help@maven.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > Eric Redmond
>> > http://codehaus.org/~eredmond
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5978571
>> Sent from the Maven - Users forum at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5987251
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Nick Veys <ps...@gmail.com>.
Jimisola:

The parameter that is getting its slashes altered, is it a String or
File in the the Mojo?  If it is just a String, try a File, I've seen
your problem before and I believe that handled it.

On 8/25/06, Jimisola Laursen <li...@jimisola.com> wrote:
>
> Hi!
>
> Are we taking about the same thing? I am taking about Java System Properties
> and not System Properties. It was not replaced when I first tried (perhaps I
> was doing something wrong). the documentation only mentions Java System
> Properties with filtering.
>
> Does the Java System Properties have a prefix or can I just use
> ${file.separator} in the configuration section?
>
> I thought I could use forward slashes for paths too, but the problem is
> caused with a "home-made" plugin. The plugin takes the output file as a
> parameter in the configuration section and I don't believe that slashes (/)
> are replaced with backslashes (\) on the fly. Should I handle this in my
> plugin perhaps?
>
> Sorry if I am missing out on something trivial here. I don't even run
> Windows myself, so I haven't tested - all I got was a bug report from a team
> member:
>
> Example:
> ${project.build.directory}/generated-resources/buildinfo-maven-${project.build.finalName}.xml
>
> This results in:
> C:\myrepository\.../generated-resources/buildinfo-maven-....
>
> Regards,
> Jimisola
>
>
> Eric Redmond wrote:
> >
> > You can use System properties. However, you don't need to use
> > file.seperator... you can just use forward slash for paths.
> >
> > Eric
> >
> > On 8/24/06, Jimisola Laursen <li...@jimisola.com> wrote:
> >>
> >>
> >> Hi!
> >>
> >> Been reading through the documentation on maven.apache.org and the book,
> >> but
> >> I can't find any information on if it is possible to use Java System
> >> Properties such as file.separator, user.name and more
> >> (
> >> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties()
> >> )
> >> in pom.xml?
> >>
> >> I have a problem with file separators because we use both Linux and
> >> Windows
> >> when developing and it therefore looks as I if I need to use
> >> ${file.separator} in our common POM.
> >>
> >> Regards,
> >> Jimisola
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5973537
> >> Sent from the Maven - Users forum at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
> >
> > --
> > Eric Redmond
> > http://codehaus.org/~eredmond
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5978571
> Sent from the Maven - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Jimisola Laursen <li...@jimisola.com>.
Hi!

Are we taking about the same thing? I am taking about Java System Properties
and not System Properties. It was not replaced when I first tried (perhaps I
was doing something wrong). the documentation only mentions Java System
Properties with filtering.

Does the Java System Properties have a prefix or can I just use
${file.separator} in the configuration section? 

I thought I could use forward slashes for paths too, but the problem is
caused with a "home-made" plugin. The plugin takes the output file as a
parameter in the configuration section and I don't believe that slashes (/)
are replaced with backslashes (\) on the fly. Should I handle this in my
plugin perhaps?

Sorry if I am missing out on something trivial here. I don't even run
Windows myself, so I haven't tested - all I got was a bug report from a team
member:

Example:
${project.build.directory}/generated-resources/buildinfo-maven-${project.build.finalName}.xml

This results in:
C:\myrepository\.../generated-resources/buildinfo-maven-....

Regards,
Jimisola


Eric Redmond wrote:
> 
> You can use System properties. However, you don't need to use
> file.seperator... you can just use forward slash for paths.
> 
> Eric
> 
> On 8/24/06, Jimisola Laursen <li...@jimisola.com> wrote:
>>
>>
>> Hi!
>>
>> Been reading through the documentation on maven.apache.org and the book,
>> but
>> I can't find any information on if it is possible to use Java System
>> Properties such as file.separator, user.name and more
>> (
>> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties()
>> )
>> in pom.xml?
>>
>> I have a problem with file separators because we use both Linux and
>> Windows
>> when developing and it therefore looks as I if I need to use
>> ${file.separator} in our common POM.
>>
>> Regards,
>> Jimisola
>> --
>> View this message in context:
>> http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5973537
>> Sent from the Maven - Users forum at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 
> 
> -- 
> Eric Redmond
> http://codehaus.org/~eredmond
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5978571
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Java System Properties in pom.xml

Posted by Eric Redmond <er...@gmail.com>.
You can use System properties. However, you don't need to use
file.seperator... you can just use forward slash for paths.

Eric

On 8/24/06, Jimisola Laursen <li...@jimisola.com> wrote:
>
>
> Hi!
>
> Been reading through the documentation on maven.apache.org and the book,
> but
> I can't find any information on if it is possible to use Java System
> Properties such as file.separator, user.name and more
> (
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties()
> )
> in pom.xml?
>
> I have a problem with file separators because we use both Linux and
> Windows
> when developing and it therefore looks as I if I need to use
> ${file.separator} in our common POM.
>
> Regards,
> Jimisola
> --
> View this message in context:
> http://www.nabble.com/Using-Java-System-Properties-in-pom.xml-tf2161474.html#a5973537
> Sent from the Maven - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Eric Redmond
http://codehaus.org/~eredmond