使用 Eclipse,某些东西不断添加 src/test/java 到类路径
Using Eclipse, something keeps adding src/test/java to the classpath
情况是这样的。我在一个 java/selenium/maven 项目中。我没有测试 class,因此 Project->Properties->Java Build Path->Source 中仅有的两个 "Source folders on build path" 是:
src/main/java 和 src/main/resources。此外,src/main/resources "Excluded" 设置为 (None).
我做了一个 Maven/Update 项目...
现在由于某些原因添加了 src/test/java 并且丢失了,并且 src/main/resouces 已更改为 **,排除了该目录中的所有文件。
我做了更改以重做所有这些,保存,做一个 Maven/Update 项目,然后再次回到那些更改。是什么不断改变我的项目的 .class 路径?
编辑以在前后添加 .settings 文件。
在执行 Maven->更新项目之前:
<?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->Update 项目后:
<?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>
注意:从问题中添加了 POM.xml:
<?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>
在 Eclipse 中,"Maven - Update Project..." 命令指示 Eclipse 根据 pom.xml
更新其自己的项目文件(.classpath
以及其他项目文件)。它不是实际的 Maven 命令。您看到的修改是由 Eclipse 添加的,基于 Java/Maven 项目的典型布局。我相信这是由 maven2Nature
或 maven2Builder
在 .project
.
中的存在控制的
你实际上并没有说明这个问题,所以我不确定你为什么要改变它。但您可能会发现这些答案很有帮助:
What does Maven Update Project do in Eclipse?
这里有两个问题:
1) 如果您使用的是 maven,则不应修改项目的 .classpath 或设置文件,因为这将由带有 m2e 插件的 eclipse 维护。
这就是为什么当您使用 "maven => update project" 时您的项目文件会从 maven 模板中更新。
2) 使用maven 是个好主意。 Maven 引入了项目的一些模板。因此,如果您使用的是 Maven,则必须接受一些特定于 Maven 的约定。
maven 项目页面上描述了这个约定。
您可以通过覆盖 maven super 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>
情况是这样的。我在一个 java/selenium/maven 项目中。我没有测试 class,因此 Project->Properties->Java Build Path->Source 中仅有的两个 "Source folders on build path" 是:
src/main/java 和 src/main/resources。此外,src/main/resources "Excluded" 设置为 (None).
我做了一个 Maven/Update 项目...
现在由于某些原因添加了 src/test/java 并且丢失了,并且 src/main/resouces 已更改为 **,排除了该目录中的所有文件。
我做了更改以重做所有这些,保存,做一个 Maven/Update 项目,然后再次回到那些更改。是什么不断改变我的项目的 .class 路径?
编辑以在前后添加 .settings 文件。
在执行 Maven->更新项目之前:
<?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->Update 项目后:
<?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>
注意:从问题中添加了 POM.xml:
<?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>
在 Eclipse 中,"Maven - Update Project..." 命令指示 Eclipse 根据 pom.xml
更新其自己的项目文件(.classpath
以及其他项目文件)。它不是实际的 Maven 命令。您看到的修改是由 Eclipse 添加的,基于 Java/Maven 项目的典型布局。我相信这是由 maven2Nature
或 maven2Builder
在 .project
.
你实际上并没有说明这个问题,所以我不确定你为什么要改变它。但您可能会发现这些答案很有帮助:
What does Maven Update Project do in Eclipse?
这里有两个问题:
1) 如果您使用的是 maven,则不应修改项目的 .classpath 或设置文件,因为这将由带有 m2e 插件的 eclipse 维护。
这就是为什么当您使用 "maven => update project" 时您的项目文件会从 maven 模板中更新。
2) 使用maven 是个好主意。 Maven 引入了项目的一些模板。因此,如果您使用的是 Maven,则必须接受一些特定于 Maven 的约定。
maven 项目页面上描述了这个约定。
您可以通过覆盖 maven super 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>