简体   繁体   English

Maven没有编译类,war文件中没有类文件

[英]Maven not compiling class and there is no class files in war file

iam converting my project to maven. 我将我的项目转换为maven。 I see in war file there is no class file available. 我在war文件中看到没有可用的类文件。

Below is the pom.xml and project structure. 下面是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>RetailProducts</groupId>
  <artifactId>RetailProducts</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>RetailProducts</name>

  <dependencies>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.7</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
        </dependency>
                <!-- Tomcat 6 need this -->
        <dependency>
            <groupId>com.sun.el</groupId>
            <artifactId>el-ri</artifactId>
            <version>1.0</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>JavaServerFaces</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.1.1</version>
      <!-- <configuration> section added to pick up the WEB-INF/web.xml inside WebContent -->
      <configuration>
         <webResources>
            <resource>
               <directory>WebContent</directory>
            </resource>
         </webResources>
      </configuration>
   </plugin>
        </plugins>
    </build>
</project>


Project structure 项目结构

在此输入图像描述

From my point of view your project structure isn't as maven expects. 从我的角度来看,你的项目结构并不像maven所期望的那样。

In order to solve your problem do the following: 为了解决您的问题,请执行以下操作:

  1. First rename your package retail.web.mbean to main.java.retail.web.mbean (after the process your package will be still named retail.web.mbean ), this will create the folder structure necessary for maven. 首先将您的软件包retail.web.mbean重命名为main.java.retail.web.mbean (在您的软件包仍将命名为retail.web.mbean的过程之后),这将创建maven所需的文件夹结构。
  2. Right click on the project, Maven > Update Project Configuration. 右键单击项目Maven>更新项目配置。

After this process you will have the same structure you had before starting the project but maven will know where to find the source code. 在此过程之后,您将拥有与启动项目之前相同的结构,但maven将知道在何处查找源代码。

Additionally, you can create a resource folder and test folders with the following structure: 此外,您可以使用以下结构创建资源文件夹和测试文件夹:

Project
  src
    main
      java
      resources
    test
      java
      resources

This would be the standard maven project structure. 这将是标准的maven项目结构。

By default Maven expects the Java sources to be in src/main/java but your project structure has the sources in src . 默认情况下,Maven希望Java源代码位于src / main / java中,但您的项目结构中包含src中的源代码。 I would recommend that to you adhere to the standard Maven directory layout. 我建议你遵守标准的Maven目录布局。

If you don't want to do that then you can use the sourceDirectory build setting as should below: 如果您不想这样做,那么您可以使用sourceDirectory构建设置,如下所示:

<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">
  ...
  <build>
    <sourceDirectory>${basedir}/src</sourceDirectory>
  </build>
</project>

You can use the following lines of code in POM.xml to include java files in war that you have created. 您可以在POM.xml中使用以下代码行来包含已创建的war中的java文件。 Bydefault war exclude .java files while packaging. Bydefault war在打包时排除.java文件。

<resources>
    <resource>
    <directory>src</directory>
    <includes>
    <include>**/*.java</include>
    </includes>
    </resource>
</resources>

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

相关问题 在哪里可以为Maven War项目添加类文件? - Where is a proper place to add class files for maven war project? 使用外部jar文件(不在maven工件中)编译maven项目 - Compiling a maven project with class from external jar file (that is not in a maven artifact) 使用maven使用主要方法(以及从属类和jar文件)为整个类创建整个项目的war文件和jar文件 - Creating a war file of the whole project and a jar file for a class with main method (along with the dependent classes and jar files) using maven 使用 maven 编译时如何使用 class 文件而不是 java 文件 - How to use class file instead of java file when compiling with maven 不在war文件中的类文件中创建struts.xml文件 - Not creating struts.xml file in class files in the war file 使用Maven进行动态类编译和加载 - Dynamic class compiling and loading with Maven 使用 Maven 编译成 WAR 时包含非 java 文件 - Including non-java files when compiling into WAR using Maven 是否可以将.cl​​ass(java)文件分别添加到现有.war文件中? - Is it possible to add .class(java) files separately to the existing .war file? Warble为什么在war文件中不包括.class文件? - Why does not Warble include .class files in war file? 将.xsl文件编译成.class文件 - Compiling .xsl files into .class files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM