0

我想从父 pom 部署到 glassfish4,但我总是收到以下错误消息:

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)]

我的父 pom 有几个模块,对于其中两个,我想将一个 war 文件部署到 glassfish。如果我将插件代码写入模块 pom 并仅执行该模块,它就可以工作。但是如果我将它移动到配置文件中的父 pom,以便我只为设置了特殊属性的模块执行它,maven 找不到插件。

父-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>

儿童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>

4

2 回答 2

2

尝试在你的父 pomglassfish-maven-plugin下移动under build -> pluginManagement

<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>

然后在你的孩子 pom中添加这个插件调用:

<plugins>
  <plugin>
      <groupId>org.glassfish.maven.plugin</groupId>
      <artifactId>maven-glassfish-plugin</artifactId>
  </plugin>
</plugins>
于 2014-04-16T11:16:36.913 回答
2

除了 tmarwen 的正确答案:

您对配置文件激活的使用有问题。

基于属性的配置文件激活仅适用于 maven 命令行或系统环境变量中提供的属性(请参阅配置文件简介)。

这意味着您不能在父级中定义您的配置文件并让它仅在子级 pom 中处于活动状态(无需在子级中进行进一步配置)(从 maven 3 开始,有一个选项,见下文)。

所以你有三个选择:

在父项中定义配置文件,覆盖子项中的激活条件:

家长:

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

孩子们:

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

使用 tmarwen 的答案

使用基于文件的激活

这是 maven 3 的新功能。在 maven 2 中,基于文件的激活仅相对于您运行 maven 的文件夹发生,即使对于多模块,在 maven 3 中,这现在是相对于当前模块的。

所以你使用:

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

此解决方案的优点是,您不必在模块中定义任何内容。

但是,您仍然应该考虑一些轻松地阻止部署的方法,并不是每个构建都必须部署。

于 2014-04-16T12:06:31.437 回答