简体   繁体   English

Maven:Maven构建中的类下缺少文件

[英]Maven: Files missing under classes in maven build

Bear with me, am new to Maven. 忍受我,对Maven还是陌生的。 So, I have this project checked in with the following structure- 因此,我使用以下结构签入了该项目:

-WebContent -网页内容
-src -src
-pom.xml -pom.xml

When I build this project through the command line, using the command- 当我通过命令行构建该项目时,请使用以下命令-

mvn clean MVN清洁
mvn package mvn包

and I get a target folder with a .war file which I deployed to the tomcat server. 我得到一个目标文件夹,其中包含.war文件,该文件已部署到tomcat服务器。 My project UI is displayed but no APIs get called. 显示我的项目UI,但未调用任何API。 But when I import the same project to Eclipse IDE and build it, I notice there are an extra set of files and folders- 但是,当我将同一个项目导入Eclipse IDE并进行构建时,我注意到还有另外一组文件和文件夹,

  • build 建立
  • .classpath .classpath
  • ImportedClasses 导入的类
  • .project 。项目
  • .settings 。设置

As well as an extra set of .xmls under classes in the target dir. 在目标目录下的类下还有一组额外的.xmls。

This is my pom.xml- 这是我的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>

Why does both builds produce seperate results from the same set of files? 为什么两个版本都从同一组文件中产生不同的结果? How do I resolve and understand this problem? 我该如何解决和理解此问题?

By default, maven package adds the default src by compiling and packaging them and adding default resource into the war file. 默认情况下,maven软件包通过编译和打包并将默认资源添加到war文件中来添加默认src。

The default location for resources in maven based web-apps is: src/main/resources If your resources are at other location it will not be added to a war file. 基于Maven的Web应用程序中资源的默认位置为:src / main / resources如果您的资源位于其他位置,则不会将其添加到war文件中。

If you wish to include another resource like any .xml file or image etc. you can mention that explicitly in pom.xml for the same. 如果您希望包括其他资源,例如任何.xml文件或图像等,则可以在pom.xml中明确提及。

Example: inside your build tag of add below: 示例:在您的添加以下构建标记中:

<resources>
 <resource>
   <directory>[your folder here]</directory>
 </resource>

The above instruction will add the resources to the root of the folder in war WEB-INF. 以上说明会将资源添加到war WEB-INF中的文件夹的根目录中。 If you wish to add them to a specific location then you can add 如果您希望将它们添加到特定位置,则可以添加

<resources>
 <resource>
   <directory>[your folder here]</directory>
   <targetPath>[you target path in WEB_INF/classes</targetPath>
 </resource>

Example: 例:

 <resource>
    <directory>src/com/ekagga/ga/config/</directory>
    <targetPath>com/ekagga/ga/config</targetPath>
    <filtering>true</filtering>
  </resource>
</resources>

Default it will add all the files like .java etc, you may need to add a filter to remove such file. 默认情况下,它将添加所有文件,例如.java等,您可能需要添加过滤器才能删除此类文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM