Question

I want to deploy to glassfish4 from the parent pom, but I always receive the following error message:

No plugin found for prefix 'glassfish' in the current project and in the plugin groups
[org.apache.maven.plugins, org.codehaus.mojo] available from the repositories 
[local (c:\Programs\Server\.m2\repository), central (http://repo.maven.apache.org/maven2)]

My parent pom has several modules and for two of them I want to deploy a war file to glassfish. If I write the plugin code into the module pom and execute only the module, it's working. But if I move it to parent pom within a profile, so that I only execute it for the modules having set a special property, maven cannot find the plugin.

Parent-pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.glassfish.javaeetutorial.firstcup</groupId>
<artifactId>firstcup</artifactId>
<version>7.0.1</version>
<packaging>pom</packaging>
<name>firstcup</name>

<scm>
    <connection>scm:svn:https://svn.java.net/svn/firstcup~svn/tags/firstcup-7.0.1</connection>
    <developerConnection>scm:svn:https://svn.java.net/svn/firstcup~svn/tags/firstcup-7.0.1</developerConnection>
</scm>
<issueManagement>
    <system>IssueTracker</system>
    <url>http://java.net/jira/browse/FIRSTCUP</url>
</issueManagement>

<modules>
    <module>firstcup-war</module>
    <module>dukes-age</module>
    <module>archetypes</module>
</modules>

<properties>
    <javaee.api.version>7.0</javaee.api.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
    <maven.war.plugin.version>2.3</maven.war.plugin.version>
    <maven.license.plugin.version>1.10.b1</maven.license.plugin.version>
    <deploy.glassfish>false</deploy.glassfish>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.plugin.version}</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <debug>true</debug>
                <debuglevel>lines,vars,source</debuglevel>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${maven.war.plugin.version}</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <version>${maven.license.plugin.version}</version>
            <configuration>
                <header>common/license.txt</header>
                <excludes>
                    <exclude>**/META-INF/**</exclude>
                    <exclude>**/WEB-INF/**</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>deploy-glassfish</id>
        <activation>
            <property>
                <name>deploy.glassfish</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.glassfish.maven.plugin</groupId>
                    <artifactId>maven-glassfish-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
                        <user>${local.glassfish.user}</user>
                        <passwordFile>${local.glassfish.passfile}</passwordFile>
                        <domain>
                            <name>${local.glassfish.domain}</name>
                            <httpPort>${local.glassfish.httpport}</httpPort>
                            <adminPort>${local.glassfish.adminport}</adminPort>
                        </domain>
                        <components>
                            <component>
                                <name>${project.name}</name>
                                <artifact>target/${project.name}-${project.version}.war</artifact>
                            </component>
                        </components>
                        <debug>true</debug>
                        <terse>false</terse>
                        <echo>true</echo>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>


<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>${javaee.api.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>java.net-maven2-repository</id>
        <name>Java.net Repository for Maven</name>
        <url>https://maven.java.net/content/repositories/staging/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>Java EE 7</id>
        <url>https://maven.java.net/content/groups/promoted/</url> 
    </repository>
</repositories>

Child-pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <artifactId>firstcup</artifactId>
    <groupId>org.glassfish.javaeetutorial.firstcup</groupId>
    <version>7.0.1</version>
</parent>

<artifactId>dukes-age</artifactId>
<groupId>org.glassfish.javaeetutorial.firstcup</groupId>
<packaging>war</packaging>
<name>dukes-age</name>

<properties>
    <deploy.glassfish>true</deploy.glassfish>
</properties>

Was it helpful?

Solution

Try to move the glassfish-maven-plugin under build -> pluginManagement under your parent pom:

<pluginManagement>
    <plugins>
            <plugin>
                <groupId>org.glassfish.maven.plugin</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
                    <user>${local.glassfish.user}</user>
                    <passwordFile>${local.glassfish.passfile}</passwordFile>
                    <domain>
                        <name>${local.glassfish.domain}</name>
                        <httpPort>${local.glassfish.httpport}</httpPort>
                        <adminPort>${local.glassfish.adminport}</adminPort>
                    </domain>
                    <components>
                        <component>
                            <name>${project.name}</name>
                            <artifact>target/${project.name}-${project.version}.war</artifact>
                        </component>
                    </components>
                    <debug>true</debug>
                    <terse>false</terse>
                    <echo>true</echo>
                </configuration>
            </plugin>
        </plugins>
</pluginManagement>

Then inside your child pom add this plugin invocation:

<plugins>
  <plugin>
      <groupId>org.glassfish.maven.plugin</groupId>
      <artifactId>maven-glassfish-plugin</artifactId>
  </plugin>
</plugins>

OTHER TIPS

In addition to tmarwen's correct answer:

Your use of profile activation is faulty.

Profile activation based on properties does only work on properties provided on the maven commandline or system environment variables (see Introduction to Profiles).

What this means is you cannot define your profile in the parent and let it only be active in a child pom (without further configuration in the child) (since maven 3, there is one option, see below).

So you have three options:

Define the profile in the parent, override the activation criteria in child:

Parent:

<profiles>
    <profile>
        <id>deploy-glassfish</id>
        <!-- no activation here -->
        <build>
        ...
        </build>
    </profile>
</profiles>

Children:

<profiles>
    <profile>
        <id>deploy-glassfish</id>
        <activation>
            <property>
                <name>deploy.glassfish</name>
                <value>true</value>
            </property>
        </activation>
     <!-- no content here -->
    </profile>
</profiles>

Use tmarwen's answer

Use file based activation

This one is new to maven 3. In maven 2, file based activation happened only relative to the folder where you run maven from, even for multimodules, in maven 3 this is now relative to the current module.

So you use:

<profiles>
    <profile>
        <id>deploy-glassfish</id>
        <file>
            <exists>${basedir}/src/main/webapp/WEB-INF/web.xml</exists>
        </file>
        <build>
        ...
        </build>
    </profile>
</profiles>

The advantage of this solution is, that you do not have to define anything in your modules.

You should, however still consider some way to comfortably prevent deployment, not every build should necessarily deploy as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top