2016-08-23 70 views
0

我設置了新的Cucumber-Maven項目。mvn clean install throws編譯失敗,但與Junit運行正常運行

當我運行我的Runner.java文件選項作爲Junit運行,同樣工作正常。 但是當我嘗試使用命令「MVN全新安裝」通過命令提示符下運行一樣,那麼它會拋出錯誤: -

C:\Users\HT1\workspace\com.pvrcucumber>mvn clean install 
[INFO] Scanning for projects... 
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for PVR_CUCUMBER:com.pvrcucumber:jar:0.0.1-SNAPSHOT 
[WARNING] 'dependencies.dependency.systemPath' for com.microsoft.sqlserver:sqljdbc4:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/config/sqljdbc4.jar will be unresolvable by dependent projects @ line 69, column 16 
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 108, column 17 
[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 com.pvrcucumber 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ com.pvrcucumber --- 
[INFO] Deleting C:\Users\HT1\workspace\com.pvrcucumber\target 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ com.pvrcucumber --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 16 resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ com.pvrcucumber --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 24 source files to C:\Users\HT1\workspace\com.pvrcucumber\target\classes 
[INFO] ------------------------------------------------------------- 
[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[5,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[10,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[11,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[19,76] cannot find symbol 
    symbol: class FindFailed 
    location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/DealsExclusives.java:[7,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/DealsExclusives.java:[36,91] cannot find symbol 
    symbol: class FindFailed 
    location: class stepdefinitions.DealsExclusives 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[14,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[15,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[16,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[66,76] cannot find symbol 
    symbol: class FindFailed 
    location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[21,17] cannot find symbol 
    symbol: class Screen 
    location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[21,35] cannot find symbol 
    symbol: class Screen 
    location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[22,17] cannot find symbol 
    symbol: class Pattern 
    location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[22,34] cannot find symbol 
    symbol: class Pattern 
    location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[94,27] cannot find symbol 
    symbol: class Screen 
    location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[94,45] cannot find symbol 
    symbol: class Screen 
    location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[95,27] cannot find symbol 
    symbol: class Pattern 
    location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[95,44] cannot find symbol 
    symbol: class Pattern 
    location: class pageObject.DealsExclusivesPage 
[INFO] 18 errors 
[INFO] ------------------------------------------------------------- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 5.447 s 
[INFO] Finished at: 2016-08-23T13:59:43+05:30 
[INFO] Final Memory: 19M/225M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project com.pvrcucumber: Compilation failure: Compilation failure: 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[5,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[10,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[11,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[19,76] cannot find symbol 
[ERROR] symbol: class FindFailed 
[ERROR] location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/DealsExclusives.java:[7,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/DealsExclusives.java:[36,91] cannot find symbol 
[ERROR] symbol: class FindFailed 
[ERROR] location: class stepdefinitions.DealsExclusives 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[14,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[15,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[16,25] package org.sikuli.script does not exist 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[66,76] cannot find symbol 
[ERROR] symbol: class FindFailed 
[ERROR] location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[21,17] cannot find symbol 
[ERROR] symbol: class Screen 
[ERROR] location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[21,35] cannot find symbol 
[ERROR] symbol: class Screen 
[ERROR] location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[22,17] cannot find symbol 
[ERROR] symbol: class Pattern 
[ERROR] location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/stepdefinitions/Cinemas.java:[22,34] cannot find symbol 
[ERROR] symbol: class Pattern 
[ERROR] location: class stepdefinitions.Cinemas 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[94,27] cannot find symbol 
[ERROR] symbol: class Screen 
[ERROR] location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[94,45] cannot find symbol 
[ERROR] symbol: class Screen 
[ERROR] location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[95,27] cannot find symbol 
[ERROR] symbol: class Pattern 
[ERROR] location: class pageObject.DealsExclusivesPage 
[ERROR] /C:/Users/HT1/workspace/com.pvrcucumber/src/main/java/pageObject/DealsExclusivesPage.java:[95,44] cannot find symbol 
[ERROR] symbol: class Pattern 
[ERROR] location: class pageObject.DealsExclusivesPage 
[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 

,我的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>PVR_CUCUMBER</groupId> 
    <artifactId>com.pvrcucumber</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>com.pvrcucumber</name> 
    <url>http://maven.apache.org</url> 

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

    <dependencies> 

     <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit --> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-junit</artifactId> 
      <version>1.2.2</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java --> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-java</artifactId> 
      <version>1.2.2</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng --> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-testng</artifactId> 
      <version>1.2.2</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/junit/junit --> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>2.53.0</version> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 

    <dependency> 
    <groupId>org.sikuli</groupId> 
    <artifactId>sikuli-api</artifactId> 
    <version>1.2.0</version> 
</dependency> 


<dependency> 
    <groupId>com.microsoft.sqlserver</groupId> 
    <artifactId>sqljdbc4</artifactId> 
    <version>4.0</version> 
    <scope>system</scope> 
    <systemPath>${project.basedir}/src/main/resources/config/sqljdbc4.jar</systemPath> 
    </dependency> 


<!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> 
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>3.14</version> 
</dependency> 

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> 
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi-ooxml</artifactId> 
    <version>3.14</version> 
</dependency> 



    </dependencies> 


    <build> 
    <plugins> 

    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.19.1</version> 
    <dependencies> 
     <dependency> 
     <groupId>org.apache.maven.surefire</groupId> 
     <artifactId>surefire-junit47</artifactId> 
     <version>2.19.1</version> 
     </dependency> 
    </dependencies> 
    </plugin> 

     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <configuration> 
      <archive> 
      <manifest> 
       <addClasspath>true</addClasspath> 
      </manifest> 
      </archive> 
     </configuration> 
     </plugin> 

</plugins> 
    </build> 
</project> 

當我運行我的Runner.java類通過Runas-> junit它工作正常,但與mvn乾淨安裝它不是。

請提出建議!

+0

什麼是您的軟件包結構? src/main/java下的源代碼是什麼? –

+0

src/main/java-包含代碼和stepdefinitions。 src/test/java-包含我的runner類和src/main/resources-contains功能文件 –

+0

你的包不在classpath中......不知道爲什麼除非我看到代碼 –

回答

0

當您運行mvn clean install時,必須在您的pom文件的依賴項部分定義編譯項目所需的所有內容。 運行junit時,必須在類路徑中定義編譯項目所需的所有內容。

在這種情況下,org.sikuli.script包可以在您的junit的類路徑中找到,但無法在您的Maven依賴項中找到。

要解決這個問題,你必須添加一個maven依賴到你的pom文件,該文件包含maven工件(通常是一個jar文件),其中包含缺少的包。

一旦找到包含缺失包的jar文件(嘗試在junit的runner類路徑中查找),可以將jar添加到本地maven存儲庫中以創建工件,然後將其包含在pom文件中。 嘗試搜索'如何將jar添加到本地maven repo'以獲得如何完成的語法。

+0

Paul: - 謝謝!你的解決方案:) –

+1

嗨Suresh,我很高興解決方案的作品。請您將我的答案標記爲「已接受」?謝謝。 –

0

解決方案:@Before構建您的組件(使用mvn乾淨安裝)。重新構建整個項目並重新構建組件

爲什麼如此: 我多次得到此錯誤。大多數時候我會嘗試單獨構建我的組件(因爲我沒有在其他地方進行更改)。

對,但最近下載的額外jar可能會受到第三方(在其組件內)所做更改的影響。在整個項目中進行完整的mvn clean install可以爲我節省很多時間

相關問題