【问题标题】:Why maven is always pointing to lower version of JRE为什么maven总是指向较低版本的JRE
【发布时间】:2015-09-29 18:23:55
【问题描述】:

我有一个 Maven 项目,其中我的驱动程序脚本是 testng 测试,当我使用 testng 套件运行测试时,它运行良好。

但是当我使用 pom.xml 或 jenkins 运行测试时,它总是抱怨说它指向较低版本,尽管我在 Eclipse 中将 JRE 和编译器配置为最新版本。

如何解决这个问题:

以下是詹金斯日志:

Started by user anonymous
Building in workspace C:\Users\Uday\.jenkins\workspace\MavenProj
FSSCM.checkout D:\FrameworkDemos\MavenHAF to C:\Users\Uday\.jenkins\workspace\MavenProj
FSSCM.check completed in 62 milliseconds
Parsing POMs
Discovered a new module MavenWebHAF:MavenWebHAF MavenWebHAF
Modules changed, recalculating dependency graph
[MavenProj] $ "C:\Program Files\Java\jdk1.8.0_60/bin/java" -cp C:\Users\Uday\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-agent-1.5.jar;E:\Softwares\apache-maven-3.3.3\boot\plexus-classworlds-2.5.2.jar;E:\Softwares\apache-maven-3.3.3/conf/logging jenkins.maven3.agent.Maven31Main E:\Softwares\apache-maven-3.3.3 C:\Users\Uday\.jenkins\war\WEB-INF\lib\remoting-2.52.jar C:\Users\Uday\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-interceptor-1.5.jar C:\Users\Uday\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.5.jar 52877
<===[JENKINS REMOTING CAPACITY]===>channel started

Executing Maven:  -B -f C:\Users\Uday\.jenkins\workspace\MavenProj\pom.xml test -Dtest=TestSuite.TestAutomationDriver

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for MavenWebHAF:MavenWebHAF:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.relevantcodes:extentreports:jar should use a variable instead of a hard-coded path E:\Programming Samples\Selenium Jars\extentreports_Updated.jar @ line 33, column 21
[WARNING] 'dependencies.dependency.systemPath' for org.monte:media:jar should use a variable instead of a hard-coded path E:\Programming Samples\Selenium Jars\MonteScreenRecorder.jar @ line 40, column 21
[WARNING] 'dependencies.dependency.systemPath' for com.sun:tools:jar should use a variable instead of a hard-coded path C:\Program Files\Java\jdk1.8.0_60\lib\tools.jar @ line 52, column 29
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenWebHAF 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenWebHAF ---

[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Uday\.jenkins\workspace\MavenProj\src\main\resources

[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenWebHAF ---

[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenWebHAF ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Uday\.jenkins\workspace\MavenProj\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenWebHAF ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 7 source files to C:\Users\Uday\.jenkins\workspace\MavenProj\target\test-classes

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Uday/.jenkins/workspace/MavenProj/src/test/java/FrameworkLibraries/FunctionLibraries/CommonFunctionLibrary.java:[244,39] strings in switch are not supported in -source 1.5
  (use -source 7 or higher to enable strings in switch)
[ERROR] /C:/Users/Uday/.jenkins/workspace/MavenProj/src/test/java/FrameworkLibraries/FunctionLibraries/CommonFunctionLibrary.java:[287,39] strings in switch are not supported in -source 1.5
  (use -source 7 or higher to enable strings in switch)
[INFO] 2 errors 
[INFO] -------------------------------------------------------------

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.643 s
[INFO] Finished at: 2015-09-29T23:47:29+05:30
[INFO] Final Memory: 24M/273M
[INFO] ------------------------------------------------------------------------

Waiting for Jenkins to finish collecting data
[JENKINS] Archiving C:\Users\Uday\.jenkins\workspace\MavenProj\pom.xml to MavenWebHAF/MavenWebHAF/0.0.1-SNAPSHOT/MavenWebHAF-0.0.1-SNAPSHOT.pom
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project MavenWebHAF: Compilation failure: Compilation failure:
[ERROR] /C:/Users/Uday/.jenkins/workspace/MavenProj/src/test/java/FrameworkLibraries/FunctionLibraries/CommonFunctionLibrary.java:[244,39] strings in switch are not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable strings in switch)
[ERROR] /C:/Users/Uday/.jenkins/workspace/MavenProj/src/test/java/FrameworkLibraries/FunctionLibraries/CommonFunctionLibrary.java:[287,39] strings in switch are not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable strings in switch)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
channel stopped

Finished: FAILURE

【问题讨论】:

    标签: java eclipse maven jenkins


    【解决方案1】:

    Maven 总是使用默认的 Java 安装。从您在系统上发布的 Java 版本的错误来看,它不是 Java 7(

    以下是此类配置的示例:

    <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>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      打开您的pom 并查看您是否在maven compiler plugin 配置中为源版本配置了较旧的Java 版本。

      如果是这样,将其设置为较新的版本将解决问题。例如:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-19
        • 2011-07-12
        • 1970-01-01
        • 1970-01-01
        • 2018-01-02
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        相关资源
        最近更新 更多