Maven似乎忽略了webapp中的源和目标

时间:2013-09-06 22:52:48

标签: java maven pom.xml

我收到“生成的servlet错误:-source 1.5中不支持try-with-resources”。根据关于该主题的另一个问题,1.5是maven的默认值,但我认为我已经在我的pom.xml中修复了它 -

<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>

  <parent>
    <groupId>com.sspo</groupId>
    <artifactId>sspo-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>website</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>website</name>

  <properties>
    <jetty.version>9.0.5.v20130815</jetty.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>${jetty.version}</version>
        <dependencies>
          <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
          </dependency>
          <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.6</version>
          </dependency>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>com.sspso</groupId>
      <artifactId>com.sspo.package1</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
      <groupId>com.sspo</groupId>
      <artifactId>com.sspo.package2</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

项目中的其他软件包可以正常使用1.7,如父pom中所示 -

<?xml version="1.0" encoding="UTF-8"?>
<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>com.sspo</groupId>
  <artifactId>sspo-parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>sspo-parent</name>  

  <modules>
    <module>try-with-resources-works-here</module>
    <module>and-here</module>
    <module>even-in-this-one</module>
    <module>website</module>
  </modules>

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

  <dependencies>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>14.0.1</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.2</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
    </dependency>
  </dependencies>
</project>

最终,我认为问题可能是“我做错了什么,maven忽略了源和目标规范?”有类似的问题,但我看到的那些问题要么没有解决,要么建议我的pom中存在的东西。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

Jetty默认使用1.5源和目标args进行JSP编译。有关将Jetty切换为使用1.7

的指示和信息,请参阅Jetty embedded and JSP compilation to 1.7?