You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by ri...@jpmchase.com on 2006/08/14 09:31:13 UTC

Newbie question on MOJOs

Hi,

I am new to Maven2. I am trying to develop plugins in Maven2 using the 
Java Plugins approach. I have seen the getting started guide on MOJOs 
(http://maven.apache.org/guides/plugin/guide-java-plugin-development.html). 
But this is too elementary. Could someone please point me to some more 
advanced guide to building MOJOs, one which contains integration with Ant 
Java APIs? I have taken a look at the AntExternal guide as well: 
http://ant.apache.org/manual/antexternal.html.

At this point, I am simply trying to use Ant's Javac.java API to compile 
my source code using a MOJO. I had the following questiions:
1. How do I get access to maven's dependency classpath (i.e. path 
containing all the dependencies defined in project's pom.xml)? In Maven 
1.x this was accessible using maven.dependency.classpath reference in 
plugin.jelly.
2. How does Maven set the java.home System Property? I have set the 
environment var "Java_Home" to the jdk directory but Maven is setting the 
java.home System property to the jre directory (i.e. <jdk_dir>/jre). Why 
is that so?

Has anyone used Ant's Javac API to do the compilation from inside a MOJO. 
If yes, could you please send me the code snippet to set the classpath and 
any other system properties?

Thanks in advance,
Ritu







-----------------------------------------
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.

Re: Newbie question on MOJOs

Posted by John Casey <ca...@gmail.com>.
Hi Ritu,

I'm not sure what your goal is, but if you're just trying to do a simple
compilation of source code, you might want to simply point your POM at the
source directory, and try calling `mvn compile`.

By default, Maven will compile the source files for you...it's part of the
default lifecycle for jar projects.

POM syntax for source directory:

<project>
  [...]
  <build>
    <sourceDirectory>relative/source/dir</sourceDirectory>
  </build>
</project>

HTH,

john

On 8/14/06, franz see <fr...@gmail.com> wrote:
>
>
> Good day to you, Ritu
>
> > Hi,
> >
> > I am new to Maven2. I am trying to develop plugins in Maven2 using the
> > Java Plugins approach. I have seen the getting started guide on MOJOs
> > (
> http://maven.apache.org/guides/plugin/guide-java-plugin-development.html).
> > But this is too elementary. Could someone please point me to some more
> > advanced guide to building MOJOs, one which contains integration with
> Ant
> > Java APIs? I have taken a look at the AntExternal guide as well:
> > http://ant.apache.org/manual/antexternal.html.
>
> Sorry, I don't know of any advance guides which integrates Ant Java APIs
> with MOJOs. But you may want to look at the source code of
> maven-antrun-plugin to see how it used the Ant Java APIs (see [1]). Who
> names, maybe it can already do what you're trying to accomplish ^_^
>
> > At this point, I am simply trying to use Ant's Javac.java API to compile
> > my source code using a MOJO. I had the following questiions:
> > 1. How do I get access to maven's dependency classpath (i.e. path
> > containing all the dependencies defined in project's pom.xml)? In Maven
> > 1.x this was accessible using maven.dependency.classpath reference in
> > plugin.jelly.
>
> code wise, you can use the following to get those classpaths
>
> * for maven.dependency.classpath and maven.compile.classpath, use
> mavenProject.getCompileClasspathElements()
> * for maven.runtime.classpath, use
> mavenProject.getRuntimeClasspathElements()
> * for maven.test.classpath, use mavenProject.getTestClasspathElements()
>
> then add reference to your Ant Project (i.e. antProject.addReference(
> "maven.compile.classpath", p) where p is of type
> org.apache.tools.ant.types.Path)
>
> Better if you take a look at executeTasks( ... ) of AbstractAntMojo (see
> [2])
>
> > 2. How does Maven set the java.home System Property? I have set the
> > environment var "Java_Home" to the jdk directory but Maven is setting
> the
> > java.home System property to the jre directory (i.e. <jdk_dir>/jre). Why
> > is that so?
>
> Maven's System properites simply comes from java.lang.System.getProperties
> ()
>
> > Has anyone used Ant's Javac API to do the compilation from inside a
> MOJO.
> > If yes, could you please send me the code snippet to set the classpath
> and
> > any other system properties?
>
> java compilation? try [3]
>
> Btw, [4] contains a list of plugins supported by Apache. Maybe what you're
> trying to do has already been done.
>
> [1]
> http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-antrun-plugin/
> [2]
>
> http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java
> [3]
> http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-compiler-plugin/
> [4]
>
> Cheers,
> Franz
> --
> View this message in context:
> http://www.nabble.com/Newbie-question-on-MOJOs-tf2101911.html#a5793568
> 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: Newbie question on MOJOs

Posted by franz see <fr...@gmail.com>.
Good day to you, Ritu

> Hi,
> 
> I am new to Maven2. I am trying to develop plugins in Maven2 using the 
> Java Plugins approach. I have seen the getting started guide on MOJOs 
> (http://maven.apache.org/guides/plugin/guide-java-plugin-development.html). 
> But this is too elementary. Could someone please point me to some more 
> advanced guide to building MOJOs, one which contains integration with Ant 
> Java APIs? I have taken a look at the AntExternal guide as well: 
> http://ant.apache.org/manual/antexternal.html.

Sorry, I don't know of any advance guides which integrates Ant Java APIs
with MOJOs. But you may want to look at the source code of
maven-antrun-plugin to see how it used the Ant Java APIs (see [1]). Who
names, maybe it can already do what you're trying to accomplish ^_^

> At this point, I am simply trying to use Ant's Javac.java API to compile 
> my source code using a MOJO. I had the following questiions:
> 1. How do I get access to maven's dependency classpath (i.e. path 
> containing all the dependencies defined in project's pom.xml)? In Maven 
> 1.x this was accessible using maven.dependency.classpath reference in 
> plugin.jelly.

code wise, you can use the following to get those classpaths

* for maven.dependency.classpath and maven.compile.classpath, use
mavenProject.getCompileClasspathElements()
* for maven.runtime.classpath, use
mavenProject.getRuntimeClasspathElements()
* for maven.test.classpath, use mavenProject.getTestClasspathElements()

then add reference to your Ant Project (i.e. antProject.addReference(
"maven.compile.classpath", p) where p is of type
org.apache.tools.ant.types.Path)

Better if you take a look at executeTasks( ... ) of AbstractAntMojo (see
[2])

> 2. How does Maven set the java.home System Property? I have set the 
> environment var "Java_Home" to the jdk directory but Maven is setting the 
> java.home System property to the jre directory (i.e. <jdk_dir>/jre). Why 
> is that so?

Maven's System properites simply comes from java.lang.System.getProperties()

> Has anyone used Ant's Javac API to do the compilation from inside a MOJO. 
> If yes, could you please send me the code snippet to set the classpath and 
> any other system properties?

java compilation? try [3]

Btw, [4] contains a list of plugins supported by Apache. Maybe what you're
trying to do has already been done.

[1] http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-antrun-plugin/
[2]
http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java
[3]
http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-compiler-plugin/
[4] 

Cheers,
Franz
-- 
View this message in context: http://www.nabble.com/Newbie-question-on-MOJOs-tf2101911.html#a5793568
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