java - 当我从命令行输入 "mvn install"时,如何将 Maven Web 应用程序配置为在 glassfish 上自动部署?

标签 java maven glassfish pom.xml

我正在使用 glassfish 和 Maven 来处理 javaee 教程。我可以让这个例子运行良好。我想做的是从头开始重新创建我已经完成的相同示例。 (通过在netbenas中打开一个新的maven项目创建

但是,通过示例,当我 mvn install 时,通过命令行,示例应用程序会自动部署在 glassfish 服务器上。我认为他的原因是示例文件已经放置在 glassfish 目录中

C:\
glassfish4
       docs
          javaee-tutorial
                       examples
                             web
                               jsf
                                 hello1 (target application)

现在我的项目正在不同的 NetBeansProjects 目录中创建

C:\
netbeansprojects
            javaee_tuts
                     practiceproject (target application)

example 项目已自动部署,但我的 practiceproject 未部署。我猜测是因为该项目不在 glassfish 目录中,或者它可能是这个和其他东西的组合,对此我不确定。我想也许我可以使用 pom.xml 以某种方式配置它,但我对 Maven 很陌生,并且对 pom 不太熟悉。

这是两个pom

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

   <parent>
      <artifactId>jsf</artifactId>
      <groupId>org.glassfish.javaeetutorial</groupId>
      <version>7.0.3</version>
   </parent>

   <groupId>org.glassfish.javaeetutorial</groupId>
   <artifactId>hello1</artifactId>
   <version>7.0.3</version>
   <packaging>war</packaging>

   <name>${project.artifactId}</name>
</project>

我的实践项目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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mavenpractice</groupId>
<artifactId>practiceproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>practiceproject</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

我可以通过netbeans来部署项目,这没问题,但我想通过命令行练习使用maven。最后用一个问题来结束:

What do I need to do to get my practice project to auto deploy on glassfish using mvn install from command line?

最佳答案

mvn install 不会进行部署,但您可以使用 cargoasadmin 等插件来帮助完成该任务。

https://github.com/Codeartisans/asadmin

http://cargo.codehaus.org/

关于java - 当我从命令行输入 "mvn install"时,如何将 Maven Web 应用程序配置为在 glassfish 上自动部署?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20040618/

相关文章:

java - Long.valueOf(java.lang.String) 和 new Long(java.lang.String) 的区别?

java - windows 10 正确安装 JVM 的 JAR 文件

java - 编译 Hadoop native - 在 Maven 插件中发现错误

testing - 禁用 Glassfish 中的自动更新检查

java - Slick2d 光照与乘法

java - 应用程序在启动时崩溃,尝试查看登录屏幕是否存在文件

java - hibernate一级缓存,直接在DB修改记录

maven - 学习Maven,被依赖注入(inject)迷惑

java - HTTPURLConnection 状态 200 但输入流为空

java - 何时调用 EJB 实体 setter