2017-07-12 89 views
1

這是情況。我在一個java/selenium/maven項目中。我沒有測試類,因此項目 - >屬性 - > Java構建路徑 - >源中僅有兩個「構建​​路徑上的源文件夾」是:使用Eclipse,東西不斷添加src/test/java到類路徑

src/main/java和src/main/resources。另外,src/main/resources「Excluded」被設置爲(None)。

我做一個Maven /更新項目...

現在出於某種原因的src/test/java下已添加和缺失,和src /主/ resouces已更改爲**,排除一切該目錄中的文件。

我做了更改,重做所有這些,保存,做一個Maven/Update項目,並再次回到這些更改。什麼讓我的項目更改我的.classpath?

編輯在添加.settings文件之前和之後。

執行Maven->更新項目之前:從問一個問題添加了pom.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry kind="src" output="target/classes" path="src/main/java"> 
     <attributes> 
     <attribute name="optional" value="true"/> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="lib" path="src/main/resources/db2jcc_license.jar"/> 
    <classpathentry kind="lib" path="src/main/resources/db2jcc4.jar"/> 
    <classpathentry kind="lib" path="src/main/resources/ojdbc6.jar"/> 
    <classpathentry kind="src" output="target/test-classes" path="src/test/java"> 
     <attributes> 
      <attribute name="optional" value="true"/> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="output" path="target/classes"/> 
</classpath> 

注:

<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry kind="src" output="target/classes" path="src/main/java"> 
     <attributes> 
      <attribute name="optional" value="true"/> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="src" output="target/classes" path="src/main/resources"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="lib" path="src/main/resources/db2jcc_license.jar"/> 
    <classpathentry kind="lib" path="src/main/resources/db2jcc4.jar"/> 
    <classpathentry kind="lib" path="src/main/resources/ojdbc6.jar"/> 
    <classpathentry kind="output" path="target/classes"/> 
</classpath> 

執行Maven->更新項目後

<?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.this.ebusiness</groupId> 
    <artifactId>test-automation-framework</artifactId> 
    <version>LOCALBUILD</version> 
    <packaging>jar</packaging> 

    <name>Test Automation Framework</name> 

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

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
       <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-resources-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-source-plugin</artifactId> 
       <executions> 
        <execution> 
        <id>attach-sources</id> 
        <goals> 
         <goal>jar</goal> 
        </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

<dependencies> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.11</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>3.4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <version>4.5.3</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.guava</groupId> 
     <artifactId>guava</artifactId> 
     <version>21.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-firefox-driver</artifactId> 
     <version>3.4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-safari-driver</artifactId> 
     <version>3.4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.logging.log4j</groupId> 
     <artifactId>log4j-api</artifactId> 
     <version>2.8.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.logging.log4j</groupId> 
     <artifactId>log4j-core</artifactId> 
     <version>2.8.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.ini4j</groupId> 
     <artifactId>ini4j</artifactId> 
     <version>0.5.4</version> 
    </dependency> 
</dependencies> 

回答

0

在Eclipse中,「Maven-Update Project ...」命令指示Eclipse根據pom.xml更新其自己的項目文件(.classpath以及其他文件)。這不是一個真正的Maven命令。基於Java/Maven項目的典型佈局,Eclipse中添加了您所看到的修改。我相信這是由maven2Naturemaven2Builder存在.project控制的。

你還沒有真正說過這個問題,所以我不知道你爲什麼要改變它。但你會發現這些問題的答案有所幫助:

What exactly does Maven Update Project do in Eclipse?

What does Maven Update Project do in Eclipse?

+0

一個大問題是它加入**到/ src目錄/主/資源,然後不包括這些文件的排除列表在生成的jar文件中,它不起作用。另一個問題是它不能成功構建,因爲它期望存在一個/ src/main/test目錄,這在我的項目中不存在。因此,jar不會被創建,依賴於這個框架的其他項目將不會生成或運行。 – GregMa

+0

您正在將'.classpath'(這隻對Eclipse很重要)與Maven POM混淆。排除'**'僅影響Eclipse內部構建器的類路徑。它不排除在使用例如JAR文件構建時包含在JAR中的資源。 'maven install'。 – TheCoolah

+0

至於缺少'/ src/main/test'搞砸你的構建,只需添加一個空目錄,Eclipse就會很開心。這只是Eclipse期望的目錄結構。我不知道這個解決方法。 – TheCoolah

0

我們這裏有兩個問題:

1)如果你正在使用maven,那麼你不應該修改的.classpath或設置你的項目文件,因爲這將通過日食與m2e插件。

這就是當您使用「maven =>更新項目」時,您的項目文件將從maven模板更新的原因。

2)使用maven是個好主意。 Maven介紹了一些項目的模板。因此,如果你使用maven,你將不得不接受一些maven特定的約定。

這個約定在maven項目頁面描述。

你可以重寫這個約定,重寫maven超級pom。

在這裏看到: http://maven.apache.org/pom.html#The_Super_POM

<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory> 

<testResources> 
     <testResource> 
     <directory>${project.basedir}/src/test/resources</directory> 
     </testResource> 
    </testResources> 
+0

問題是,我沒有直接編輯.classpath或設置文件,而是通過Eclipse右鍵單擊項目,選擇「屬性」並在「源」選項卡中執行更改。然後我檢查生成的.settings以查看它的外觀。 – GregMa

+0

如果您運行「Maven - 更新項目...」,請確保取消選中「從pom.xml更新項目配置」選項。這就是改寫.classpath(通過Project - Properties - Java Build Path創建的)。 – TheCoolah

相關問題