当前位置: 首页 > 面试题库 >

1.3版不支持Java泛型和注释(travis集成)

咸星波
2023-03-14
问题内容

我正在尝试将我的github Java / PHP项目与travis-ci环境集成。这是我的travis配置:

language: java
jdk:
  - openjdk7
  - oraclejdk7
script: mvn test

下面是travis打印的输出:

Using worker: bluebox-linux-1.worker.travis-ci.org:travis-linux-9
$ git clone --depth=50 --branch=master git://github.com/tkoomzaaskz/wealthy-laughing-duck.git tkoomzaaskz/wealthy-laughing-duck
Cloning into 'tkoomzaaskz/wealthy-laughing-duck'...
remote: Counting objects: 458, done.
remote: Compressing objects: 100% (263/263), done.
remote: Total 458 (delta 156), reused 390 (delta 96)
Receiving objects: 100% (458/458), 458.40 KiB, done.
Resolving deltas: 100% (156/156), done.
$ cd tkoomzaaskz/wealthy-laughing-duck
$ git checkout -qf 47d1ef528f19ad6d01288ac9a3d4c550a79b14f4
$ jdk_switcher use openjdk7
Switching to OpenJDK7 (java-1.7.0-openjdk-amd64), JAVA_HOME will be set to /usr/lib/jvm/java-7-openjdk-amd64
update-alternatives: error: no alternatives for apt.
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
$ java -version
java version "1.7.0_15"
OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
$ javac -version
javac 1.7.0_15
$ mvn install --quiet -DskipTests=true
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project wealthy-laughing-duck: Compilation failure: Compilation failure:
[ERROR] /home/travis/build/tkoomzaaskz/wealthy-laughing-duck/src/main/java/com/blogspot/symfonyworld/wealthylaughingduck/dao/OutcomeDao.java:[19,8] error: generics are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /home/travis/build/tkoomzaaskz/wealthy-laughing-duck/src/main/java/com/blogspot/symfonyworld/wealthylaughingduck/model/Income.java:[12,1] error: annotations are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/travis/build/tkoomzaaskz/wealthy-laughing-duck/src/main/java/com/blogspot/symfonyworld/wealthylaughingduck/model/User.java:[10,1] error: annotations are not supported in -source 1.3

输出显示我使用的Java版本太旧,无法使用注释和泛型。但是这些并不是什么新鲜事物,它们必须以某种方式得到支持(我想)。我一直在查看travis /
java文档,但没有找到有关Java版本的选项(因此我尝试使用其他jdks)。谁能指出我该在travis配置文件中放什么?

编辑:

在@hertzsprung之后,我运行mvn help:effective- pom并返回以下输出(实际上,注释sourcetarget属性均未定义maven-compiler-plugin-我该怎么办?):

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Generated by Maven Help Plugin on 2013-03-24T08:15:13                  -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
<!--                                                                        -->
<!-- ====================================================================== -->

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Effective POM for project                                              -->
<!-- 'com.blogspot.symfony-world:wealthy-laughing-duck:jar:1.0-SNAPSHOT'    -->
<!--                                                                        -->
<!-- ====================================================================== -->

<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.blogspot.symfony-world</groupId>
  <artifactId>wealthy-laughing-duck</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>wealthy-laughing-duck</name>
  <url>http://maven.apache.org</url>
  <build>
    <sourceDirectory>/var/www/github/wealthy-laughing-duck/src/main/java</sourceDirectory>
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>/var/www/github/wealthy-laughing-duck/src/test/java</testSourceDirectory>
    <outputDirectory>/var/www/github/wealthy-laughing-duck/target/classes</outputDirectory>
    <testOutputDirectory>/var/www/github/wealthy-laughing-duck/target/test-classes</testOutputDirectory>
    <resources>
      <resource>
        <mergeId>resource-0</mergeId>
        <directory>/var/www/github/wealthy-laughing-duck/src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <mergeId>resource-1</mergeId>
        <directory>/var/www/github/wealthy-laughing-duck/src/test/resources</directory>
      </testResource>
    </testResources>
    <directory>/var/www/github/wealthy-laughing-duck/target</directory>
    <finalName>wealthy-laughing-duck-1.0-SNAPSHOT</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.6</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-4</version>
        </plugin>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>2.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.4</version>
        </plugin>
        <plugin>
          <artifactId>maven-ear-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-ejb-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>2.6.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-plugin-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-rar-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.0-beta-8</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-source-plugin</artifactId>
          <version>2.0.4</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.4.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.1-beta-1</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-help-plugin</artifactId>
        <version>2.2</version>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libthrift</artifactId>
      <version>0.9.0</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.3</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>4.1.10.Final</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.24</version>
    </dependency>
  </dependencies>
  <reporting>
    <outputDirectory>/var/www/github/wealthy-laughing-duck/target/site</outputDirectory>
  </reporting>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16 seconds
[INFO] Finished at: Sun Mar 24 20:15:13 CET 2013
[INFO] Final Memory: 11M/60M
[INFO] ------------------------------------------------------------------------

这是我的原始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>com.blogspot.symfony-world</groupId>
    <artifactId>wealthy-laughing-duck</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>wealthy-laughing-duck</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libthrift</artifactId>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <artifactId>slf4j-api</artifactId>
            <groupId>org.slf4j</groupId>
            <type>jar</type>
            <version>1.7.3</version>
        </dependency>
        <dependency>
            <artifactId>hibernate-core</artifactId>
            <groupId>org.hibernate</groupId>
            <type>jar</type>
            <version>4.1.10.Final</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.24</version>
        </dependency>
    </dependencies>
</project>

问题答案:

请尝试在pom.xml中为Maven构建配置包含以下代码。我和自己有同样的问题,这似乎对我有用:

<build>
    <pluginManagement>
         <plugins>
             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>2.3.2</version>
                 <configuration>
                     <source>1.6</source>
                     <target>1.6</target>
                     <compilerArgument></compilerArgument>
                 </configuration>
             </plugin>
         </plugins>
    </pluginManagement>
</build>


 类似资料:
  • 问题内容: 为什么Java中的泛型只能用于类,而不能用于原始类型? 例如,这可以正常工作: 但这是不允许的: 问题答案: ava中的泛型是一个完全编译时的结构-编译器将所有泛型使用转换为正确的类型。这是为了保持与以前的JVM运行时的向后兼容性。 这个: 变成(大致): 因此,任何用作泛型的东西都必须可转换为Object(在此示例中返回),而原始类型则不是。因此它们不能用于泛型。

  • 为什么Java中的泛型可以处理类而不能处理基元类型? 例如,这个操作很好: 但这是不允许的:

  • 静态编程语言是否支持像这样的java注释,因为我无法让它工作。我可以用注释颜色,但实际上没有得到该注释的lint检查。 例子 传递,不显示线头。应使用R颜色显示皮棉。colorPrimary,不与

  • 下面是错误指定的错误示例。我应该如何修复它,为什么我得到一个错误?

  • 目标 无明确目标 知识点 学习使用 travis-ci 对项目进行持续集成测试 (https://travis-ci.org/ ) 课程内容 首先来看看这个项目:https://github.com/Ricardo-Li/node-practice-3 (图1) 类似这样的 badges,在很多项目中都可以看到。前者是告诉我们,这个项目的测试目前是通过的;后者是告诉我们,这个测试的行覆盖率是多少。

  • 我试图在我的Eclipse J2EE透视图中使用Tomcat 7部署一个非常简单的HTTPServlet项目。我得到错误“Tomcat版仅支持J2EE 1.2、1.3、1.4和Java EE 5和6 Web模块”。我已经尝试修改我的org . eclipse . wst . common . project . facet . core . XML文件,就像这里提到的那样,但是这似乎不能解决问题。