我想从父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找不到该插件。
父,聚甲醛
<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>
答案 0 :(得分:2)
尝试移动构建下的glassfish-maven-plugin
- &gt;您的父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>
然后在 child pom 中添加此插件调用:
<plugins>
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
</plugin>
</plugins>
答案 1 :(得分:2)
除了tmarwen的正确答案:
您对个人资料激活的使用有误。
基于属性的配置文件激活仅适用于maven命令行或系统环境变量上提供的属性(请参阅Introduction to Profiles)。
这意味着您不能在父级中定义您的个人资料,只允许它在子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>
这是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>
此解决方案的优点是,您无需在模块中定义任何内容。
但是,您应该考虑采用某种方式轻松阻止部署,而不是每个版本都必须部署。