gpt4 book ai didi

maven - 如何使用 Maven 创建 .war 文件?

转载 作者:行者123 更新时间:2023-12-03 16:00:52 26 4
gpt4 key购买 nike

这是我的项目,由以下 Maven 模块组成:

模型、服务、网络

在目标文件夹下仅创建 Web 模块 war 文件。 .web模块由 Controller 和网页组成

我的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aitrich.learnware</groupId>
<artifactId>Learnware</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Learnware Cloud Application - Master</name>
<description>This is parent pom for Learnware Cloud Application, where all the generic configurations are defined.</description>

<modules>
<module>LearnwareWeb</module>
<module>LearnwareModel</module>
<module>LearnwareServices</module>
</modules>
<organization>
<name>Aitrich Technologies</name>
<url>http://www.aitrich.com</url>
</organization>

<developers>
<developer>
<id>1</id>
<name>Shaheer</name>
<roles>
<role>Technical Leader</role>
<role>Developer</role>
</roles>
</developer>
<developer>
<id>2</id>
<name>Shinas</name>
<roles>
<role>Team Leader</role>
<role>Developer</role>
</roles>
</developer>
<developer>
<id>3</id>
<name>Prasanth AR</name>
<roles>
<role>Developer</role>
</roles>
</developer>
<developer>
<id>4</id>
<name>Jijesh VU</name>
<roles>
<role>Developer</role>
</roles>
</developer>
</developers>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javaee6.web.spec.version>2.0.0.Final</javaee6.web.spec.version>
<spring.version>3.1.2.RELEASE</spring.version>
<hibernate.version>4.1.1.Final</hibernate.version>
<junit.version>4.11</junit.version>
<java-version>1.7</java-version>
<jboss.as.maven.plugin.version>7.4.Final</jboss.as.maven.plugin.version>
</properties>

<repositories>
<repository>
<id>springsource-repo</id>
<name>SpringSource Repository</name>
<url>http://repo.springsource.org/release</url>
</repository>
<repository>
<id>jboss-releases-repository</id>
<name>JBoss Releases Repository</name>
<url>
https://repository.jboss.org/nexus/content/repositories/releases/
</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>com.aitrich.learnware</groupId>
<artifactId>LearnwareModel</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>com.aitrich.learnware</groupId>
<artifactId>LearnwareServices</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>com.aitrich.learnware</groupId>
<artifactId>LearnwareWeb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<scope>compile</scope>
</dependency>

<!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-web-6.0 stack (you can read this
as the JBoss stack of the Java EE Web Profile 6 APIs) -->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-web-6.0</artifactId>
<version>${javaee6.web.spec.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as @Email -->
<!-- Hibernate Validator is shipped in JBoss AS 7 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<type>jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>

</dependencies>
</dependencyManagement>

<build>
<directory>${project.basedir}/target</directory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<!--Plugin for JBossAs7 -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${jboss.as.maven.plugin.version}</version>
<inherited>true</inherited>
<configuration>
<hostname>localhost</hostname>
<port>9999</port>
<filename>${project.build.finalName}.war</filename>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

最佳答案

我假设 web 模块依赖于模型和服务模块。然后在 web 模块中你应该使用包装

<packaging>war</packaging>

这将创建一个包含所有内容的 WAR。见 War Plugin创建的 WAR 包含其依赖项。您不能单独部署模型或服务项目。

如果您的项目已经打包为 war,请检查模型和服务的 JAR 是否在 WAR/WEB-INF/lib 文件夹中。如果是的话,一切都很好, war 已经准备好部署了。

关于maven - 如何使用 Maven 创建 .war 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17164896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com