Maven WAR 部署

Maven WAR deploy

我需要 Maven 专家的建议: 我有一个项目,我想使用 mvn clean package command -Denv=rec deploy

通过 SFTP 部署到 Glassfish/Payara 服务器

这是我的pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>fr.inrae.sicpa</groupId>
  <artifactId>TraceLBSoapWS</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <encoding>UTF-8</encoding>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.version>3.1</maven.compiler.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>

  <dependencies>
    <!-- https://mvnrepository.com/artifact/jakarta.jws/jakarta.jws-api -->
    <dependency>
      <groupId>jakarta.jws</groupId>
      <artifactId>jakarta.jws-api</artifactId>
      <version>2.1.0</version>
    </dependency>
  </dependencies>

  <profiles>
    <!-- Profil pour l'environnement de recette -->
    <profile>
      <id>rec</id>
      <activation>
        <property>
          <name>env</name>
          <value>rec</value>
        </property>
      </activation>
      <build>
        <resources>
          <resource>
            <directory>${basedir}/resources/rec</directory>
          </resource>
        </resources>
      </build>
      <distributionManagement>
        <repository>
         <id>my-server-recette</id>
         <url>sftp://my.server.fr:/data/apps/payara/autodeploy/group-recette/webdistri</url>
        </repository>
      </distributionManagement>
    </profile>
     <!-- Profil pour l'environnement de production -->
    <profile>
      <id>prod</id>
      <activation>
        <property>
          <name>env</name>
          <value>prod</value>
        </property>
      </activation>
      <build>
        <resources>
          <resource>
            <directory>${basedir}/resources/prod</directory>
          </resource>
        </resources>
      </build>
      <distributionManagement>
        <repository>
         <id>my-server-production</id>
         <url>sftp://my.server.fr:/data/apps/payara/autodeploy/group-production/webdistri</url>
        </repository>
      </distributionManagement>
    </profile>
  </profiles>

  <build>
    <finalName>TraceLBSoapWS</finalName>
    <sourceDirectory>${basedir}/src</sourceDirectory>
    <testSourceDirectory>${basedir}/test</testSourceDirectory>
    <resources>
      <resource>
        <directory>${basedir}/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>*.properties</include>
          <include>*.xml</include>
        </includes>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>11</source>
          <target>11</target>
          <release>11</release>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
          <!-- exclude web.xml file -->
          <failOnMissingWebXml>false</failOnMissingWebXml>
          <warSourceExcludes>WEB-INF/web.xml</warSourceExcludes>
        </configuration>
      </plugin>
    </plugins>
    <extensions>
      <!-- https://mvnrepository.com/artifact/org.apache.maven.wagon/wagon-ssh -->
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ssh</artifactId>
        <version>3.4.0</version>
      </extension>
    </extensions>
  </build>
</project>

不幸的是,当我启动我的 maven 命令时,部署的不是 WAR,而是整个项目。 我如何才能将 WAR 部署到我的 Glassfish/Payara 服务器?

感谢您的回答

蒂埃里


编辑:我得到的请求:“使用maven,编译、测试、打包并部署war存档在payara的autodeploy文件夹中”

感谢@tgdavies 给我的曲目 (非常感谢),我设法使用 org.apache.maven.wagon:wagon-ssh 扩展名完成了我想做的事情,并且org.codehaus.mojo:wagon-maven-plugin 插件在一起

下面是我在 pom.mxl 中的配置方式:

    <extensions>
      <!-- https://mvnrepository.com/artifact/org.apache.maven.wagon/wagon-ssh -->
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId> wagon-ssh</artifactId>
        <version>3.4.0</version>
      </extension>
    </extensions>
    </plugins>
      <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/wagon-maven-plugin -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId> car-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>rec</id>
            <phase>deploy</phase>
            <goyals
              <goal>upload-single</goal>
            </goals>
            <configuration>
              <fromFile>${project.build.directory}/${project.build.finalName}.${project.packaging}</fromFile>
              <url>scp://user@my.server.fr:/data/apps/payara/autodeploy/group-recette</url>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

这里是编译、测试、打包和部署的命令:

mvn clean package -Denv=rec wagon:upload-single@rec

希望我的回答可以帮助其他有此特定需求的人。

祝你有愉快的一天

蒂埃里