[英]Maven: Files missing under classes in maven build
忍受我,对Maven还是陌生的。 因此,我使用以下结构签入了该项目:
-网页内容
-src
-pom.xml
当我通过命令行构建该项目时,请使用以下命令-
MVN清洁
mvn包
我得到一个目标文件夹,其中包含.war文件,该文件已部署到tomcat服务器。 显示我的项目UI,但未调用任何API。 但是,当我将同一个项目导入Eclipse IDE并进行构建时,我注意到还有另外一组文件和文件夹,
- 建立
- .classpath
- 导入的类
- 。项目
- 。设置
在目标目录下的类下还有一组额外的.xmls。
这是我的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>GenericApp</groupId>
<artifactId>GenericApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency><!-- https://mvnrepository.com/artifact/commons-net/commons-net -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.json/javax.json-api -->
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20171018</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
为什么两个版本都从同一组文件中产生不同的结果? 我该如何解决和理解此问题?
默认情况下,maven软件包通过编译和打包并将默认资源添加到war文件中来添加默认src。
基于Maven的Web应用程序中资源的默认位置为:src / main / resources如果您的资源位于其他位置,则不会将其添加到war文件中。
如果您希望包括其他资源,例如任何.xml文件或图像等,则可以在pom.xml中明确提及。
示例:在您的添加以下构建标记中:
<resources>
<resource>
<directory>[your folder here]</directory>
</resource>
以上说明会将资源添加到war WEB-INF中的文件夹的根目录中。 如果您希望将它们添加到特定位置,则可以添加
<resources>
<resource>
<directory>[your folder here]</directory>
<targetPath>[you target path in WEB_INF/classes</targetPath>
</resource>
例:
<resource>
<directory>src/com/ekagga/ga/config/</directory>
<targetPath>com/ekagga/ga/config</targetPath>
<filtering>true</filtering>
</resource>
</resources>
默认情况下,它将添加所有文件,例如.java等,您可能需要添加过滤器才能删除此类文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.