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 にはいくつかのモジュールがあり、そのうちの 2 つについて、war ファイルを Glassfish にデプロイしたいと考えています。プラグイン コードをモジュール pom に記述し、モジュールのみを実行すると、機能します。しかし、プロファイル内の親 pom に移動して、特別なプロパティを設定したモジュールに対してのみ実行すると、maven はプラグインを見つけることができません。

親ポム:

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

チャイルドポン:

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

build -> pluginManagement親 pomglassfish-maven-pluginの下に移動してみてください:

<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 以降、1 つのオプションがあります。以下を参照してください)。

したがって、次の 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 に答える