2

I converted a dynamic web project into a maven project by right-clicking on the project and choosing Configure -> Convert to Maven Project. I added below dependency jar in pom.xml.

<dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>3.1.0</version>
            <scope>test</scope>
        </dependency>

Then, right clicked project -> Run as -> maven install. The installation was successful.

Now all the jars and classes are available under the Maven Dependencies section. Below is screenshot of my project structure.

Project structure

Below is the screenshot of maven dependency section.

Maven dependencies section

However, I am unable to import any package or class form the dependency jars into any of my Java class (Ex: HttpServices.java) in src folder. I am unable to use the jars although they are downloaded.

I tried updating Maven project (Force clearing snapshots), clean project, build project but nothing worked. I have no errors in the project. Also, when I added the jars directly into the build path (using add external jars i.e without maven) it worked perfectly fine. Please help in resolving the problem.

Note: Other Java-maven projects are working fine. Problem is only with this converted maven project. I am using Eclipse Java EE IDE for Web Developers. Version: Photon Release (4.8.0) and jdk 8

Below is the generated pom.xml. Compiler and war plugins were automatically generated when I converted the project to maven. I only added the dependency.

<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>executeAutomation</groupId>
  <artifactId>executeAutomation</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>3.1.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Below is the class path entry for maven.

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
Priya S
  • 21
  • 1
  • 6
  • Because of `test` everything of this dependency is available only in test source, not in the main source. Does removing `test` and right-click the project and _Maven > Update Project..._ fix your issue? – howlger Apr 19 '19 at 10:33

1 Answers1

0

Because of <scope>test</scope> everything of this dependency is available only in test source, not in the main source.

Remove <scope>test</scope>, right-click the project and choose Maven > Update Project....

More about classpath separation for test sources in Eclipse:

howlger
  • 31,050
  • 11
  • 59
  • 99