You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jvsrvcs <jv...@gmail.com> on 2013/10/16 01:50:04 UTC

Maven profiles question

I really do not understand any of the documentation related to the
<execution> plugin.

If I do something like:
  $mvn -P deploy

I need to:
 1. build the project (meaning I just want target/myproj.jar to exist
 2. Run a java program like:   $java -jar target/myproj.jar <some_options>

so I want to create a profile that will do both.  I realize that simply $mvn
install will build the target/myproj.jar but how would I add that to a maven
profile so that it does both the mvn install and runs $java -jar
target/myproj.jar <opts>

?

Any help would be appreciated, all of the documentation and examples I have
tried are not leading me to a solution.



--
View this message in context: http://maven.40175.n5.nabble.com/Maven-profiles-question-tp5773102.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: Maven profiles question

Posted by Anders Hammar <an...@hammar.net>.
No, don't use profiles. They are evil and shouldn't be used!

Please remember that Maven is a build tool. Don't try to do too much.
If the Java program is to be run during build, then you should bind that
plugin to the build lifecycle. You would then just have to execute "mvn
install" for example. Very simple and very much a build task.
If it is something outside of the build, then what you want to do
essentially is to first execute a Maven build and then use Maven as a
"utility tool" (i.e. execute one specific plugin goal). Don't use profiles
for this as it will stuff too much into the pom and confuse people. What
you should do is just accept a slightly longer execution command (e.g. "mvn
install exec:java") or put this "long" command into a shell script (or bat
file) and execute that script.
The exec:java you will configure in the pluginManagement section of the pom
(or just stuff the properties on the command line in the script instead).

Profiles are (almost) always the wrong solution,
/Anders


On Wed, Oct 16, 2013 at 2:55 AM, Russell Gold <ru...@gold-family.us> wrote:

> Do you mean that you always want to run this program whenever you build
> it? Or you only want to run it when you activate the profile? Unless you do
> something unusual, "install" will always cause the jar to be created and
> installed in your local repository.
>
> You might try adding to your pom something like:
>
> <profiles>
>     <profile>
>         <id>run</id>
>         <build>
>             <plugins>
>                 <plugin>
>                     <groupId>org.codehaus.mojo</groupId>
>                     <artifactId>exec-maven-plugin</artifactId>
>                     <version>1.2.1</version>
>                     <executions>
>                         <execution>
>                             <phase>install</phase>
>                             <goals>
>                                 <goal>java</goal>
>                             </goals>
>                             <configuration>
>                                 <mainClass>MyProgramName</mainClass>
>                             </configuration>
>                         </execution>
>                     </executions>
>                 </plugin>
>             </plugins>
>         </build>
>     </profile>
> </profiles>
>
> You can then build and run the program with:
>
>         mvn install -Prun
>
>
> BTW, (ahem) my video course on maven, linked below, has received some good
> reviews, if you're looking for more information. And I do cover profiles
> and the execution element.
>
> - Russ
>
> On Oct 15, 2013, at 7:50 PM, Jvsrvcs <jv...@gmail.com> wrote:
>
> > I really do not understand any of the documentation related to the
> > <execution> plugin.
> >
> > If I do something like:
> >  $mvn -P deploy
> >
> > I need to:
> > 1. build the project (meaning I just want target/myproj.jar to exist
> > 2. Run a java program like:   $java -jar target/myproj.jar <some_options>
> >
> > so I want to create a profile that will do both.  I realize that simply
> $mvn
> > install will build the target/myproj.jar but how would I add that to a
> maven
> > profile so that it does both the mvn install and runs $java -jar
> > target/myproj.jar <opts>
> >
> > ?
> >
> > Any help would be appreciated, all of the documentation and examples I
> have
> > tried are not leading me to a solution.
> >
> >
> >
> > --
> > View this message in context:
> http://maven.40175.n5.nabble.com/Maven-profiles-question-tp5773102.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
> >
>
> -----------------
> Author, Getting Started with Apache Maven <
> http://www.packtpub.com/getting-started-with-apache-maven/video>
>
> Come read my webnovel, Take a Lemon <http://www.takealemon.com>,
> and listen to the Misfile radio play <
> http://www.fuzzyfacetheater.com/misfile/>!
>
>
>
>
>
>
>
>

Re: Maven profiles question

Posted by Russell Gold <ru...@gold-family.us>.
Do you mean that you always want to run this program whenever you build it? Or you only want to run it when you activate the profile? Unless you do something unusual, "install" will always cause the jar to be created and installed in your local repository.

You might try adding to your pom something like:

<profiles>
    <profile>
        <id>run</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.2.1</version>
                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <mainClass>MyProgramName</mainClass>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

You can then build and run the program with:

	mvn install -Prun


BTW, (ahem) my video course on maven, linked below, has received some good reviews, if you're looking for more information. And I do cover profiles and the execution element.

- Russ

On Oct 15, 2013, at 7:50 PM, Jvsrvcs <jv...@gmail.com> wrote:

> I really do not understand any of the documentation related to the
> <execution> plugin.
> 
> If I do something like:
>  $mvn -P deploy
> 
> I need to:
> 1. build the project (meaning I just want target/myproj.jar to exist
> 2. Run a java program like:   $java -jar target/myproj.jar <some_options>
> 
> so I want to create a profile that will do both.  I realize that simply $mvn
> install will build the target/myproj.jar but how would I add that to a maven
> profile so that it does both the mvn install and runs $java -jar
> target/myproj.jar <opts>
> 
> ?
> 
> Any help would be appreciated, all of the documentation and examples I have
> tried are not leading me to a solution.
> 
> 
> 
> --
> View this message in context: http://maven.40175.n5.nabble.com/Maven-profiles-question-tp5773102.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
> 

-----------------
Author, Getting Started with Apache Maven <http://www.packtpub.com/getting-started-with-apache-maven/video>

Come read my webnovel, Take a Lemon <http://www.takealemon.com>, 
and listen to the Misfile radio play <http://www.fuzzyfacetheater.com/misfile/>!