1

Here is the situation. I am in a java/selenium/maven project. I do not have a test class, thus the only two "Source folders on build path" in Project->Properties->Java Build Path->Source are:

src/main/java and src/main/resources. Also, the src/main/resources "Excluded" is set to (None).

I do a Maven/Update Project...

Now for some reason src/test/java has been added and is missing, and src/main/resouces has been changed to **, which excludes all the files in that directory.

I make the changes to redo all of this, save, do a Maven/Update Project, and again, back to those changes. What keeps changing my .classpath for my projects?

Edited to add the .settings file before and after.

Before executing a Maven->Update Project:

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

After executing a Maven->Update Project:

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

NOTE: Added the POM.xml from a question asked:

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

GregMa
  • 740
  • 2
  • 10
  • 25

2 Answers2

1

In Eclipse, the "Maven - Update Project..." command instructs Eclipse to update its own project files (.classpath and maybe others) based on pom.xml. It is not an actual Maven command. The modifications you are seeing are added by Eclipse, based on the typical layout of a Java/Maven project. I believe this is controlled by the presence of maven2Nature or maven2Builder in .project.

You haven't actually stated a problem with this so I'm not sure why you'd want to change it. But you may find these answers helpful:

What exactly does Maven Update Project do in Eclipse?

What does Maven Update Project do in Eclipse?

TheCoolah
  • 519
  • 1
  • 4
  • 16
  • One big problem is it's adding ** to the exclusion list of /src/main/resources, which then does not include those files in the resulting jar file and it doesn't work. The other problem is that it doesn't build successfully since it's expecting a /src/main/test directory to exist, which in my project doesn't exist. Thus the jar isn't created and the other projects that depend on this framework won't build or run. – GregMa Jul 12 '17 at 20:58
  • You are confusing the purpose of `.classpath` (which only matters to Eclipse) with the Maven POM. The exclusion of `**` only affects the classpath for Eclipse's internal builder. It does not exclude the resources from being included in a JAR when built with e.g. `maven install`. – TheCoolah Jul 12 '17 at 21:51
  • As for the missing `/src/main/test` screwing up your build, just add an empty directory and Eclipse will be happy. This is simply what Eclipse expects the directory structure to look like. I don't know of a workaround for that. – TheCoolah Jul 12 '17 at 21:53
  • Thank you Coolah! This answered my question. – GregMa Jul 12 '17 at 22:42
0

We have two issues here:

1) If you are using maven, then you should not modify the .classpath or settings files of your project because this will be maintained by eclipse with the m2e Plugin.

This is why your project files are getting updated from the maven template when you use "maven => update project".

2) Using maven is a good idea. Maven introduces some templates of a project. Thus if you are using maven, you will have to accept some maven specific conventions.

This conventions are described on the maven project page.

You can how ever override this conventions, by overriding the maven super pom.

See here: http://maven.apache.org/pom.html#The_Super_POM

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

and

 <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
      </testResource>
    </testResources>
Marcinek
  • 2,144
  • 1
  • 19
  • 25
  • The thing is, I'm not editing the .classpath or settings file directly, but through Eclipse by right clicking on the project, selecting "properties" and doing the changes in the "Source" tab. Then I am checking the resulting .settings to see what it looks like. – GregMa Jul 12 '17 at 21:05
  • If you run "Maven - Update Project...", make sure to uncheck the option "Update project configuration from pom.xml". That's what is overwriting your changes to .classpath (which were made via Project - Properties - Java Build Path). – TheCoolah Jul 12 '17 at 23:27