You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by deusaquilus <de...@gmail.com> on 2011/10/18 05:27:38 UTC

Programmatically get maven properties

I'm trying to use the maven programmatic APIs to get the properties of the
default profile (i.e. the stuff in Project->Properties->XYZ) and return them
as a Java 'Properties' object, so far with no luck. First I thought of
trying to use the maven invoker e.g:



That just seems to return null. The other way I tried was using the maven
builder APIs like so:



That causes a "mavenTools: null" exception to be thrown from the
MavenProject class.
How do I get this to work?

--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-get-maven-properties-tp4912280p4912280.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Programmatically get maven properties

Posted by sizu <sc...@gmail.com>.
It would be helpful to have a link to a single class file with a main method
to run an example of this.  I couldn't get this code to work.

Also, a link to the dependencies necessary.  How many jars does this code
use and what are the links?



--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-get-maven-properties-tp4912280p5773156.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: DefaultProjectBuilder ... mavenTools: null [Was: Re: Programmatically get maven properties]

Posted by Barrie Treloar <ba...@gmail.com>.
On 8 January 2014 09:00, juliangeo <ju...@gmail.com> wrote:
> Hi!
>
> I'm new to Maven and I've been struggling with this for a while. I just need
> to be able to programmatically build a project from a pom file in order to
> retrieve its relevant information. I am not using, nor want to, a maven
> plugin, just need this functionality as part of my application.
>
> I've tried the code you successfully got to work but no luck so far. I still
> get the "mavenTools: null" from the repositoryManager being null. Am I
> missing something? Should I run this on some kind of special environment?
>
> I'd appreciate any help as I'm really lost here.
[del]
>>>>> I'd be surprised if that worked.
>>>>>
>>>>> Maven makes heavy use of dependency injection via Plexus and chances
>>>>> are you haven't set up some component that is being used.

Your answer is already here.

You just can't use the classes outside of the Maven environment
without also setting up all the other dependencies that are needed by
that class.
And as noted, this is done by Dependency Injection (via Plexus).
You will need to look at MavenArtifactRepository and see what other
objects need to be instantiated and set into it for it to work
properly.

Your use case is not something others are really trying to do, so you
are unlikely to find someone with the knowledge to help.

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


Re: DefaultProjectBuilder ... mavenTools: null [Was: Re: Programmatically get maven properties]

Posted by juliangeo <ju...@gmail.com>.
Hi! 

I'm new to Maven and I've been struggling with this for a while. I just need
to be able to programmatically build a project from a pom file in order to
retrieve its relevant information. I am not using, nor want to, a maven
plugin, just need this functionality as part of my application.

I've tried the code you successfully got to work but no luck so far. I still
get the "mavenTools: null" from the repositoryManager being null. Am I
missing something? Should I run this on some kind of special environment?

I'd appreciate any help as I'm really lost here.

Thanks in advance.


Max Spring wrote
> Yes, having a projectBuilder in the Mojo did the trick.
> Thank you!
> The complete working example is down below.
> -Max
> 
> package org.example;
> 
> import java.io.File;
> 
> import org.apache.maven.model.Model;
> import org.apache.maven.model.building.ModelBuildingRequest;
> import org.apache.maven.plugin.AbstractMojo;
> import org.apache.maven.plugin.MojoExecutionException;
> import org.apache.maven.project.DefaultProjectBuildingRequest;
> import org.apache.maven.project.MavenProject;
> import org.apache.maven.project.ProjectBuilder;
> import org.apache.maven.project.ProjectBuildingResult;
> import org.sonatype.aether.RepositorySystemSession;
> 
> /**
>   * run with: mvn $groupId:$artifactId:$version:fetch-pom
> -DpomFile=$pomFile
>   *
>   * @goal fetch-pom
>   */
> public class FetchModelMojo extends AbstractMojo{
> 
>    /**
>     * Current repository/network configuration of Maven.
>     * @parameter default-value="${repositorySystemSession}"
>     * @readonly
>     */
>    private RepositorySystemSession repoSession;
> 
>    /**
>     * @component
>     */
>    private ProjectBuilder projectBuilder;
> 
>    /**
>     * @parameter expression="${pomFile}" default-value=""
>     */
>    private String pomFile;
> 
>    public void execute() throws MojoExecutionException {
>      try {
>        DefaultProjectBuildingRequest req = new
> DefaultProjectBuildingRequest();
>        req.setRepositorySession(repoSession);
>       
> req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT);
>        ProjectBuildingResult res = projectBuilder.build(new
> File(pomFile),req);
> 
>        // do something with the project
>        MavenProject prj = res.getProject();
>        System.out.println("prj=" + prj);
>        Model model = prj.getModel();
>        System.out.println("id="+model.getId());
>      } catch (Exception e) {
>        throw new MojoExecutionException(e.getMessage(), e);
>      }
>    }
> }
> 
> 
> On 02/10/2012 01:19 PM, Olivier Lamy wrote:
>> Hello,
>>
>> You must probably use:
>>
>>      /**
>>       * @component
>>       */
>>      private ProjectBuilder projectBuilder;
>>
>> 2012/2/10 Max Spring&lt;

> m2spring@

> &gt;:
>>> I'm running into the same "mavenTools: null" problem, but my code sits
>>> in a
>>> Maven 3.0.3 mojo:
>>>
>>>   public class MyMojo extends AbstractMojo{
>>>
>>>     /** @parameter default-value="${repositorySystemSession}" */
>>>     private RepositorySystemSession repoSession;
>>>
>>>     public void execute() throws MojoExecutionException{
>>>       DefaultProjectBuilder builder = new DefaultProjectBuilder();
>>>       DefaultProjectBuildingRequest req = new
>>> DefaultProjectBuildingRequest();
>>>       req.setRepositorySession(repoSession);
>>>       builder.build(new File("my-pom.xml"),req);
>>>
>>>       MavenProject prj = req.getProject();
>>>       Model model = prj.getModel();
>>>     }
>>>   }
>>>
>>> It barfs with
>>>
>>>   Caused by: java.lang.IllegalArgumentException: mavenTools: null
>>>     at org.apache.maven.project.MavenProject.
> <init>
> (MavenProject.java:249)
>>>     at
>>> org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:128)
>>>     at
>>> org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:102)
>>>     at MyMojo.execute(MyMojo.java:59)
>>>
>>> This is because repositorySystem in DefaultProjectBuilder is null, i.e.
>>> hasn't been injected:
>>>
>>>     @Requirement
>>>     private RepositorySystem repositorySystem;
>>>
>>> How can I get the right repositorySystem injected?
>>>
>>> Context:
>>> I'm essentially trying to do the M2E "Import Project" use case, but
>>> completely outside of Eclipse.
>>> I want to populate a workspace using the SCM pointer given by a POM
>>> fetched
>>> from the group repository.
>>>
>>> Thanks!
>>> -Max
>>>
>>>
>>> On 10/18/2011 04:59 AM, Barrie Treloar wrote:
>>>>
>>>> On Tue, Oct 18, 2011 at 10:02 PM, deusaquilus&lt;

> deusaquilus@

> &gt;
>>>>   wrote:
>>>>>
>>>>> Here's what I'm doing:
>>>>>
>>>>> File pom = new File("pom.xml");
>>>>> DefaultProjectBuildingRequest request = new
>>>>> DefaultProjectBuildingRequest();
>>>>> DefaultProjectBuilder builder = new DefaultProjectBuilder();
>>>>>
>>>>> String mavenHome = System.getenv("M2_HOME");
>>>>> ArtifactRepository localRepository = new MavenArtifactRepository(
>>>>>         "local",
>>>>>         new File(mavenHome +
>>>>> "/repository").toURI().toURL().toString(),
>>>>>         new DefaultRepositoryLayout(),
>>>>>         new ArtifactRepositoryPolicy(),
>>>>>         new ArtifactRepositoryPolicy());
>>>>> request.setLocalRepository(localRepository);
>>>>> MavenProject project = builder.build(pom, request).getProject();
>>>>> Properties properties = project.getProperties();
>>>>>
>>>>> Trouble is it's giving me errors with "mavenTools: null"
>>>>
>>>>
>>>> I'd be surprised if that worked.
>>>>
>>>> Maven makes heavy use of dependency injection via Plexus and chances
>>>> are you haven't set up some component that is being used.
>>>>
>>>> What is your actual use case.  I dont see why you would want to expose
>>>> Maven properties as a Java properties object...
>>>>
>>>> ---------------------------------------------------------------------





--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-get-maven-properties-tp4912280p5780906.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: DefaultProjectBuilder ... mavenTools: null [Was: Re: Programmatically get maven properties]

Posted by Max Spring <m2...@springdot.org>.
Yes, having a projectBuilder in the Mojo did the trick.
Thank you!
The complete working example is down below.
-Max

package org.example;

import java.io.File;

import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingResult;
import org.sonatype.aether.RepositorySystemSession;

/**
  * run with: mvn $groupId:$artifactId:$version:fetch-pom -DpomFile=$pomFile
  *
  * @goal fetch-pom
  */
public class FetchModelMojo extends AbstractMojo{

   /**
    * Current repository/network configuration of Maven.
    * @parameter default-value="${repositorySystemSession}"
    * @readonly
    */
   private RepositorySystemSession repoSession;

   /**
    * @component
    */
   private ProjectBuilder projectBuilder;

   /**
    * @parameter expression="${pomFile}" default-value=""
    */
   private String pomFile;

   public void execute() throws MojoExecutionException {
     try {
       DefaultProjectBuildingRequest req = new DefaultProjectBuildingRequest();
       req.setRepositorySession(repoSession);
       req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT);
       ProjectBuildingResult res = projectBuilder.build(new File(pomFile),req);

       // do something with the project
       MavenProject prj = res.getProject();
       System.out.println("prj=" + prj);
       Model model = prj.getModel();
       System.out.println("id="+model.getId());
     } catch (Exception e) {
       throw new MojoExecutionException(e.getMessage(), e);
     }
   }
}


On 02/10/2012 01:19 PM, Olivier Lamy wrote:
> Hello,
>
> You must probably use:
>
>      /**
>       * @component
>       */
>      private ProjectBuilder projectBuilder;
>
> 2012/2/10 Max Spring<m2...@springdot.org>:
>> I'm running into the same "mavenTools: null" problem, but my code sits in a
>> Maven 3.0.3 mojo:
>>
>>   public class MyMojo extends AbstractMojo{
>>
>>     /** @parameter default-value="${repositorySystemSession}" */
>>     private RepositorySystemSession repoSession;
>>
>>     public void execute() throws MojoExecutionException{
>>       DefaultProjectBuilder builder = new DefaultProjectBuilder();
>>       DefaultProjectBuildingRequest req = new
>> DefaultProjectBuildingRequest();
>>       req.setRepositorySession(repoSession);
>>       builder.build(new File("my-pom.xml"),req);
>>
>>       MavenProject prj = req.getProject();
>>       Model model = prj.getModel();
>>     }
>>   }
>>
>> It barfs with
>>
>>   Caused by: java.lang.IllegalArgumentException: mavenTools: null
>>     at org.apache.maven.project.MavenProject.<init>(MavenProject.java:249)
>>     at
>> org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:128)
>>     at
>> org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:102)
>>     at MyMojo.execute(MyMojo.java:59)
>>
>> This is because repositorySystem in DefaultProjectBuilder is null, i.e.
>> hasn't been injected:
>>
>>     @Requirement
>>     private RepositorySystem repositorySystem;
>>
>> How can I get the right repositorySystem injected?
>>
>> Context:
>> I'm essentially trying to do the M2E "Import Project" use case, but
>> completely outside of Eclipse.
>> I want to populate a workspace using the SCM pointer given by a POM fetched
>> from the group repository.
>>
>> Thanks!
>> -Max
>>
>>
>> On 10/18/2011 04:59 AM, Barrie Treloar wrote:
>>>
>>> On Tue, Oct 18, 2011 at 10:02 PM, deusaquilus<de...@gmail.com>
>>>   wrote:
>>>>
>>>> Here's what I'm doing:
>>>>
>>>> File pom = new File("pom.xml");
>>>> DefaultProjectBuildingRequest request = new
>>>> DefaultProjectBuildingRequest();
>>>> DefaultProjectBuilder builder = new DefaultProjectBuilder();
>>>>
>>>> String mavenHome = System.getenv("M2_HOME");
>>>> ArtifactRepository localRepository = new MavenArtifactRepository(
>>>>         "local",
>>>>         new File(mavenHome + "/repository").toURI().toURL().toString(),
>>>>         new DefaultRepositoryLayout(),
>>>>         new ArtifactRepositoryPolicy(),
>>>>         new ArtifactRepositoryPolicy());
>>>> request.setLocalRepository(localRepository);
>>>> MavenProject project = builder.build(pom, request).getProject();
>>>> Properties properties = project.getProperties();
>>>>
>>>> Trouble is it's giving me errors with "mavenTools: null"
>>>
>>>
>>> I'd be surprised if that worked.
>>>
>>> Maven makes heavy use of dependency injection via Plexus and chances
>>> are you haven't set up some component that is being used.
>>>
>>> What is your actual use case.  I dont see why you would want to expose
>>> Maven properties as a Java properties object...
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
>
>


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


Re: DefaultProjectBuilder ... mavenTools: null [Was: Re: Programmatically get maven properties]

Posted by Olivier Lamy <ol...@apache.org>.
Hello,

You must probably use:

    /**
     * @component
     */
    private ProjectBuilder projectBuilder;

2012/2/10 Max Spring <m2...@springdot.org>:
> I'm running into the same "mavenTools: null" problem, but my code sits in a
> Maven 3.0.3 mojo:
>
>  public class MyMojo extends AbstractMojo{
>
>    /** @parameter default-value="${repositorySystemSession}" */
>    private RepositorySystemSession repoSession;
>
>    public void execute() throws MojoExecutionException{
>      DefaultProjectBuilder builder = new DefaultProjectBuilder();
>      DefaultProjectBuildingRequest req = new
> DefaultProjectBuildingRequest();
>      req.setRepositorySession(repoSession);
>      builder.build(new File("my-pom.xml"),req);
>
>      MavenProject prj = req.getProject();
>      Model model = prj.getModel();
>    }
>  }
>
> It barfs with
>
>  Caused by: java.lang.IllegalArgumentException: mavenTools: null
>    at org.apache.maven.project.MavenProject.<init>(MavenProject.java:249)
>    at
> org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:128)
>    at
> org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:102)
>    at MyMojo.execute(MyMojo.java:59)
>
> This is because repositorySystem in DefaultProjectBuilder is null, i.e.
> hasn't been injected:
>
>    @Requirement
>    private RepositorySystem repositorySystem;
>
> How can I get the right repositorySystem injected?
>
> Context:
> I'm essentially trying to do the M2E "Import Project" use case, but
> completely outside of Eclipse.
> I want to populate a workspace using the SCM pointer given by a POM fetched
> from the group repository.
>
> Thanks!
> -Max
>
>
> On 10/18/2011 04:59 AM, Barrie Treloar wrote:
>>
>> On Tue, Oct 18, 2011 at 10:02 PM, deusaquilus<de...@gmail.com>
>>  wrote:
>>>
>>> Here's what I'm doing:
>>>
>>> File pom = new File("pom.xml");
>>> DefaultProjectBuildingRequest request = new
>>> DefaultProjectBuildingRequest();
>>> DefaultProjectBuilder builder = new DefaultProjectBuilder();
>>>
>>> String mavenHome = System.getenv("M2_HOME");
>>> ArtifactRepository localRepository = new MavenArtifactRepository(
>>>        "local",
>>>        new File(mavenHome + "/repository").toURI().toURL().toString(),
>>>        new DefaultRepositoryLayout(),
>>>        new ArtifactRepositoryPolicy(),
>>>        new ArtifactRepositoryPolicy());
>>> request.setLocalRepository(localRepository);
>>> MavenProject project = builder.build(pom, request).getProject();
>>> Properties properties = project.getProperties();
>>>
>>> Trouble is it's giving me errors with "mavenTools: null"
>>
>>
>> I'd be surprised if that worked.
>>
>> Maven makes heavy use of dependency injection via Plexus and chances
>> are you haven't set up some component that is being used.
>>
>> What is your actual use case.  I dont see why you would want to expose
>> Maven properties as a Java properties object...
>>
>> ---------------------------------------------------------------------
>> 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
>



-- 
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy

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


DefaultProjectBuilder ... mavenTools: null [Was: Re: Programmatically get maven properties]

Posted by Max Spring <m2...@springdot.org>.
I'm running into the same "mavenTools: null" problem, but my code sits in a Maven 3.0.3 mojo:

   public class MyMojo extends AbstractMojo{

     /** @parameter default-value="${repositorySystemSession}" */
     private RepositorySystemSession repoSession;

     public void execute() throws MojoExecutionException{
       DefaultProjectBuilder builder = new DefaultProjectBuilder();
       DefaultProjectBuildingRequest req = new DefaultProjectBuildingRequest();
       req.setRepositorySession(repoSession);
       builder.build(new File("my-pom.xml"),req);

       MavenProject prj = req.getProject();
       Model model = prj.getModel();
     }
   }

It barfs with

   Caused by: java.lang.IllegalArgumentException: mavenTools: null
     at org.apache.maven.project.MavenProject.<init>(MavenProject.java:249)
     at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:128)
     at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:102)
     at MyMojo.execute(MyMojo.java:59)

This is because repositorySystem in DefaultProjectBuilder is null, i.e. hasn't been injected:

     @Requirement
     private RepositorySystem repositorySystem;

How can I get the right repositorySystem injected?

Context:
I'm essentially trying to do the M2E "Import Project" use case, but completely outside of Eclipse.
I want to populate a workspace using the SCM pointer given by a POM fetched from the group repository.

Thanks!
-Max


On 10/18/2011 04:59 AM, Barrie Treloar wrote:
> On Tue, Oct 18, 2011 at 10:02 PM, deusaquilus<de...@gmail.com>  wrote:
>> Here's what I'm doing:
>>
>> File pom = new File("pom.xml");
>> DefaultProjectBuildingRequest request = new DefaultProjectBuildingRequest();
>> DefaultProjectBuilder builder = new DefaultProjectBuilder();
>>
>> String mavenHome = System.getenv("M2_HOME");
>> ArtifactRepository localRepository = new MavenArtifactRepository(
>>         "local",
>>         new File(mavenHome + "/repository").toURI().toURL().toString(),
>>         new DefaultRepositoryLayout(),
>>         new ArtifactRepositoryPolicy(),
>>         new ArtifactRepositoryPolicy());
>> request.setLocalRepository(localRepository);
>> MavenProject project = builder.build(pom, request).getProject();
>> Properties properties = project.getProperties();
>>
>> Trouble is it's giving me errors with "mavenTools: null"
>
> I'd be surprised if that worked.
>
> Maven makes heavy use of dependency injection via Plexus and chances
> are you haven't set up some component that is being used.
>
> What is your actual use case.  I dont see why you would want to expose
> Maven properties as a Java properties object...
>
> ---------------------------------------------------------------------
> 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: Programmatically get maven properties

Posted by Barrie Treloar <ba...@gmail.com>.
On Tue, Oct 18, 2011 at 10:02 PM, deusaquilus <de...@gmail.com> wrote:
> Here's what I'm doing:
>
> File pom = new File("pom.xml");
> DefaultProjectBuildingRequest request = new DefaultProjectBuildingRequest();
> DefaultProjectBuilder builder = new DefaultProjectBuilder();
>
> String mavenHome = System.getenv("M2_HOME");
> ArtifactRepository localRepository = new MavenArtifactRepository(
>        "local",
>        new File(mavenHome + "/repository").toURI().toURL().toString(),
>        new DefaultRepositoryLayout(),
>        new ArtifactRepositoryPolicy(),
>        new ArtifactRepositoryPolicy());
> request.setLocalRepository(localRepository);
> MavenProject project = builder.build(pom, request).getProject();
> Properties properties = project.getProperties();
>
> Trouble is it's giving me errors with "mavenTools: null"

I'd be surprised if that worked.

Maven makes heavy use of dependency injection via Plexus and chances
are you haven't set up some component that is being used.

What is your actual use case.  I dont see why you would want to expose
Maven properties as a Java properties object...

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


Re: Programmatically get maven properties

Posted by Jörg Schaible <jo...@scalaris.com>.
deusaquilus wrote:

> Here's what I'm doing:
> 
> File pom = new File("pom.xml");
> DefaultProjectBuildingRequest request = new
> DefaultProjectBuildingRequest(); DefaultProjectBuilder builder = new
> DefaultProjectBuilder();
> 
> String mavenHome = System.getenv("M2_HOME");
> ArtifactRepository localRepository = new MavenArtifactRepository(
>         "local",
>         new File(mavenHome + "/repository").toURI().toURL().toString(),


BTW: *My* repository is not at this location and most of my colleagues 
configured it to be somewhere else also ...


>         new DefaultRepositoryLayout(),
>         new ArtifactRepositoryPolicy(),
>         new ArtifactRepositoryPolicy());
> request.setLocalRepository(localRepository);
> MavenProject project = builder.build(pom, request).getProject();
> Properties properties = project.getProperties();
> 
> Trouble is it's giving me errors with "mavenTools: null"
> 
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Programmatically-get-maven-properties-
tp4912280p4913348.html
> Sent from the Maven - Users mailing list archive at Nabble.com.



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


Re: Programmatically get maven properties

Posted by deusaquilus <de...@gmail.com>.
Here's what I'm doing:

File pom = new File("pom.xml");
DefaultProjectBuildingRequest request = new DefaultProjectBuildingRequest();
DefaultProjectBuilder builder = new DefaultProjectBuilder();

String mavenHome = System.getenv("M2_HOME");
ArtifactRepository localRepository = new MavenArtifactRepository(
        "local",
        new File(mavenHome + "/repository").toURI().toURL().toString(),
        new DefaultRepositoryLayout(),
        new ArtifactRepositoryPolicy(),
        new ArtifactRepositoryPolicy());
request.setLocalRepository(localRepository);
MavenProject project = builder.build(pom, request).getProject();
Properties properties = project.getProperties();

Trouble is it's giving me errors with "mavenTools: null"

--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-get-maven-properties-tp4912280p4913348.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Programmatically get maven properties

Posted by Barrie Treloar <ba...@gmail.com>.
On Tue, Oct 18, 2011 at 2:22 PM, Brian Topping <to...@codehaus.org> wrote:
> The code you put in your original email didn't make it to the list, maybe it was formatted somehow.
>
> What I think you are looking for is:
>
>> /** @parameter default-value="${project}" */
>> private org.apache.maven.project.MavenProject mavenProject;
>
> This will give you the MavenProject object, which you can dereference to find the properties.

Also check out the articles on Plugin development at
http://maven.apache.org/guides/index.html - Section "Plugins"

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


Re: Programmatically get maven properties

Posted by Brian Topping <to...@codehaus.org>.
The code you put in your original email didn't make it to the list, maybe it was formatted somehow.  

What I think you are looking for is:

> /** @parameter default-value="${project}" */
> private org.apache.maven.project.MavenProject mavenProject;

This will give you the MavenProject object, which you can dereference to find the properties.

HTH, Brian

On Oct 17, 2011, at 11:27 PM, deusaquilus wrote:

> I'm trying to use the maven programmatic APIs to get the properties of the
> default profile (i.e. the stuff in Project->Properties->XYZ) and return them
> as a Java 'Properties' object, so far with no luck. First I thought of
> trying to use the maven invoker e.g:
> 
> 
> 
> That just seems to return null. The other way I tried was using the maven
> builder APIs like so:
> 
> 
> 
> That causes a "mavenTools: null" exception to be thrown from the
> MavenProject class.
> How do I get this to work?
> 
> --
> View this message in context: http://maven.40175.n5.nabble.com/Programmatically-get-maven-properties-tp4912280p4912280.html
> Sent from the Maven - Users mailing list archive 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