0

我收到“生成的 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.xml 中存在的问题。

任何帮助,将不胜感激。

4

1 回答 1

0

默认情况下,Jetty 使用 1.5 源和目标参数进行 JSP 编译。看到Jetty 嵌入和 JSP 编译到 1.7?有关将 Jetty 切换为使用 1.7 的指针和信息

于 2013-09-07T04:15:19.330 回答