我实现了一个公共模块,该模块是战争,例如common_module.war。我需要在另一个测试应用程序中使用此common_module.war。在我的本地日食中,当我将common_module.war作为测试应用程序的依赖关系时,我可以访问所有JSPS&测试应用程序中的common_module.war的Java类。到目前为止还不错。
现在问题是为了在服务器上部署。我将common_module.war上传到了我的公司文物文件夹。并在存储库路径中绑定了该路径。现在测试应用程序无法访问common_module.war的JSP。
我在这里做错了什么?
错误是 - 我在测试应用程序中包括公共模块的JSP。我本身可以看到找不到红色标记错误JSP。
<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>test_group_id</groupId>
<artifactId>test_artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>test</name>
<description>test</description>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>my_company_name</id>
<url>path_to_my_company_artifactory</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>common_module_group_id</groupId>
<artifactId>common_module_artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<outputDirectory>${project.build.directory}/../package/dependencies/jbossews/webapps</outputDirectory>
<warSourceDirectory>/src/main/webapp</warSourceDirectory>
<webXml>srcmainwebappWEB-INFweb.xml</webXml>
<attachClasses>true</attachClasses>
<classesClassifier>classes</classesClassifier>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</project>
在我看来,您正在尝试实现web-fragment
。这是一个可以包含在Web应用程序的Web-Inf/lib目录中的JAR文件(不是战争文件)。它可能包含与WAR文件相同的组件,包括JSP;它只是包装的不同。
JAR文件应包含一个META-INF/web-fragment.xml
文件,并且应在META-INF/resources
目录中打包JSP。Servlet容器将在此目录中处理JSP文件,就像它们在战争文件的根源一样。web-fragment.xml
本质上是普通Web.xml文件的子集。
这是Servlet 3.0 功能。
请参阅Java Servlet规范3.0/3.1的§8.2和§10.5。
战争覆盖功能帮助我解决了这个问题。现在工作正常。