【问题标题】:Maven Java EE ConfigurationMaven Java EE 配置
【发布时间】:2014-06-04 17:20:56
【问题描述】:

在我的 maven 项目中,我有这个 Effective POM:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>spring</groupId>
  <artifactId>example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>example</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.0.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.ws</groupId>
      <artifactId>spring-ws-core</artifactId>
      <version>2.1.4.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-web</artifactId>
      <version>3.2.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-config</artifactId>
      <version>3.2.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>4.3.5.Final</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>5.1.0.Final</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>4.0.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>4.0.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <sourceDirectory>C:\Users\Kleber\Downloads\Projetos\example\src\main\java</sourceDirectory>
    <scriptSourceDirectory>C:\Users\Kleber\Downloads\Projetos\example\src\main\scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\Users\Kleber\Downloads\Projetos\example\src\test\java</testSourceDirectory>
    <outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\classes</outputDirectory>
    <testOutputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>C:\Users\Kleber\Downloads\Projetos\example\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>C:\Users\Kleber\Downloads\Projetos\example\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>C:\Users\Kleber\Downloads\Projetos\example\target</directory>
    <finalName>example-0.0.1-SNAPSHOT</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <url>http://localhost:8080/manager/text</url>
          <server>TomcatServer</server>
          <path>/webappExample</path>
          <username>user001</username>
          <password>123</password>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <id>default-clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>install</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-testResources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <executions>
          <execution>
            <id>default-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>site</phase>
            <goals>
              <goal>site</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
          <reportPlugins>
            <reportPlugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
            </reportPlugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
  </reporting>
</project>

此时,在我的 Eclipse IDE 的标记选项卡中,出现了这个错误:

Description Resource    Path    Location    Type
Dynamic Web Module 3.0 requires Java 1.6 or newer.  example     line 1  Maven Java EE Configuration Problem
One or more constraints have not been satisfied.    example     line 1  Maven Java EE Configuration Problem

我尝试在我的项目的构建路径中修复此配置(在属性/Java 构建路径中),但是当我运行 Maven > 更新项目时,此选项的值返回到前一个。

我应该在哪里更改此选项以修复此错误?

【问题讨论】:

标签: java eclipse maven


【解决方案1】:
  1. 转到项目Build Path 并将Java 库版本更改为1.7
  2. 转到 Eclipse 首选项 -> Java -> 编译器 -> 将合规级别更改为 1.7
  3. 右键单击项目 -> 属性 -> 项目构面
  4. 取消选中Dynamic Web Module,然后点击应用(如果有,也取消选中JavaServer Faces
  5. Java facet 版本更改为1.7 并点击应用
  6. 添加Dyanmic Web Module v3.0,申请。

Eclipse 的构面配置有问题。确保在检查和取消检查构面之间不断点击Apply

链接:

  • Cannot change version of project facet Dynamic Web Module to 3.0?
  • Change version of project facet Dynamic Web Module to 2.5
  • 【讨论】:

    • 非常感谢。它帮助了我。
    • 谢谢,我做了你在这里提到的,可以将其更改为 3.0 版,但即使在关闭、打开、清理和构建项目之后,错误消息也没有消失。所以我只是右键单击它们以手动删除它们。现在该项目有效!多亏了 buggy Eclipse,这个 bug 浪费了我 3 个小时的时间!
    • 我上面有 1 和 2。我所做的唯一更改是 Java facet 版本,这似乎对我来说已经完成了。动态 Web 模块似乎正在从 Maven 手中接管,所以我将其排除在外。现在一切都好,谢谢。
    【解决方案2】:

    GGrec 的解决方案对我不起作用。我设法通过添加到 pom.xml 来解决这个问题:

    <build>
         <finalName>finalName</finalName>
         <plugins>
    
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source> <!-- yours Java version -->
                    <target>1.8</target> <!-- yours Java version -->
                </configuration>
            </plugin>
    
        </plugins>
    </build>
    

    更新: 此外,我发现每次在 pom.xml 上运行 mvn install 命令时,它都会覆盖以前的配置。正确的解决方案是从 pom.xml 中删除此版本并在 eclipse 选项中进行设置,或者仅使用 pom.xml 中的配置。

    【讨论】:

    • 在“右键单击项目 > Maven > 更新项目”后这对我有用
    • 只添加这一行:3.1 为我工作;保存 pom.xml 后自动构建工作区,然后错误消失。
    【解决方案3】:

    在执行上述故障排除步骤后。更新您的 Maven 项目。

    右键单击您的项目--> Maven--> 更新项目

    或者只是 Alt+f5。

    希望这可能对某人有所帮助。

    【讨论】:

      【解决方案4】:

      作为 Kefas,我将 java 版本指定为 1.7,它可以工作!

       <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
               <source>1.7</source> 
               <target>1.7</target> 
          </configuration>
      </plugin>
      

      【讨论】:

        【解决方案5】:

        以上建议对我有帮助! 右键单击项目 -> 属性 -> 项目构面,然后将 Java 构面版本更改为 1.7。

        如果不行,在pom.xml中添加如下代码:

        <build>
            <finalName>finalName</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.7</source> <!-- yours Java version -->
                        <target>1.7</target> <!-- yours Java version -->
                    </configuration>
                </plugin>
            </plugins>
        </build>
        

        保存 pom.xml。

        然后,右键单击项目-->Maven-->更新项目。

        【讨论】:

          【解决方案6】:

          这听起来可能很傻,但我只是做了 Project->Clean 然后 Maven->Update。

          解决了这个问题。

          【讨论】:

            【解决方案7】:

            将版本更改为 3.1 和标签和 1.7

             <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                 <source>1.7</source> 
                 <target>1.7</target> 
            </configuration>
            

            【讨论】:

              【解决方案8】:

              我使用的是 java 1.8。修复了以下操作。

              从 pom 中删除:

              <plugin>
                          <artifactId>maven-compiler-plugin</artifactId>
                          <version>3.5.1</version>
                          <configuration>
                              <source>1.8</source>
                              <target>1.8</target>
                          </configuration>
                      </plugin>
              

              它会抱怨 pom 不是最新的。 使用快速修复更新然后你会得到一大堆错误。

              重新添加到 pom:

              <plugin>
                          <artifactId>maven-compiler-plugin</artifactId>
                          <version>3.5.1</version>
                          <configuration>
                              <source>1.8</source>
                              <target>1.8</target>
                          </configuration>
                      </plugin>
              

              更新了maven,所有错误都被清除了。

              【讨论】:

                【解决方案9】:

                这对我有用:

                <build>
                    <pluginManagement>
                        <plugins>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>3.3</version>
                                <configuration>
                                    <source>1.8</source>
                                    <target>1.8</target>
                                </configuration>
                            </plugin>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-war-plugin</artifactId>
                                <version>2.6</version>
                                <configuration>
                                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                                    <warName>mfp</warName>
                                    <failOnMissingWebXml>false</failOnMissingWebXml>
                                </configuration>
                            </plugin>
                        </plugins>
                    </pluginManagement>
                    <finalName>myprojectname</finalName>
                </build>
                

                【讨论】:

                  【解决方案10】:

                  我不得不将 Window->Preferences->Maven-> User Settings 中的 maven 设置重置为“C:\Development\apache-maven-3.5.3\conf\settings.xml”。

                  【讨论】:

                    【解决方案11】:

                    正确的答案是: - 只是一件简单的事情 大多数情况下,您无法将动态 Web 模块版本更改为 3.0 .. 它必须默认设置为 2.3 或 2.4,否则。它不会工作 右键单击项目-> 首选项-> 项目方面-> 取消选中动态 Web 模块并将版本更改为 3.0 然后检查它。而且我认为您必须更改最新版本(即:1.7 或更高版本)。之后点击应用并关闭按钮。

                    然后更新 maven 项目.. 右键单击​​项目选择 maven -> 更新项目。 对于我们 80% 的人来说,错误仍然会继续..

                    真正的解决方案就在这里 1> 转到你的工作空间文件夹 2>然后转到您的项目文件夹 3> 检查 .settings 文件(有时它可能被隐藏然后取消隐藏它..(如此罕见的机会) 4> 进入那个 .settings 文件,然后检查 org.eclipse.wst.common.project.facet.core.xml 文件并使用记事本++或类似的东西进行编辑..在此处输入代码 5>这是里面的代码

                    <?xml version="1.0" encoding="UTF-8"?>
                    <faceted-project>
                      <fixed facet="wst.jsdt.web"/>
                      <installed facet="java" version="1.5"/>
                      <installed facet="jst.web" version="2.4"/>
                      <installed facet="wst.jsdt.web" version="1.0"/>
                    </faceted-project>
                    

                    像这样把jst.web版本改成3.0

                    <?xml version="1.0" encoding="UTF-8"?>
                    <faceted-project>
                      <fixed facet="wst.jsdt.web"/>
                      <installed facet="java" version="1.5"/>
                      <installed facet="jst.web" version="3.0"/>
                      <installed facet="wst.jsdt.web" version="1.0"/>
                    </faceted-project>
                    

                    然后最后更新maven ..然后重启eclipse或者其他IDE

                    【讨论】:

                      【解决方案12】:

                      我在 pom.xml 中添加了下面的代码行并且它工作了。

                      <properties>
                              <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
                      </properties>
                      
                      猜你喜欢
                      • 2011-09-06
                      • 1970-01-01
                      • 2019-04-02
                      • 1970-01-01
                      • 1970-01-01
                      • 2013-02-13
                      • 1970-01-01
                      • 1970-01-01
                      • 2011-04-18
                      相关资源
                      最近更新 更多