简体   繁体   English

Maven项目是通过Eclipse Update Project而不是pom.xml进行编译的?

[英]Maven project is getting compiled by Eclipse Update Project but not by pom.xml?

I am new to Maven and I have to update my Maven project every time before running the same via pom.xml or testng.xml 我是Maven的新手,每次必须通过pom.xml或testng.xml运行Maven项目之前都要更新我的Maven项目。

Whenever I run my project after Maven clean, Update Project and then Maven Test, it works fine. 每当我在Maven清理,更新项目然后进行Maven测试之后运行项目时,它都可以正常工作。 However, if I try to directly run with clean and test it gives me classpath errors.' 但是,如果我尝试直接运行clean并进行测试,则会出现类路径错误。 Clean goal is clearing the target and then maven fails to compile, however, issue doesn't occur if I do update project via Eclipse. 干净的目标是清除目标,然后maven无法编译,但是,如果我通过Eclipse更新项目,则不会发生问题。 Tried updating testng and maven surefire plugin. 尝试更新testng和maven surefire插件。 Below is my pom 以下是我的pom

<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>Complete_POM</groupId>
    <artifactId>Complete_POM</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
<suiteXmlFile>testng.xml</suiteXmlFile>
    </properties>
    <dependencies>
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.13.1</version>
    <scope>test</scope>
</dependency>           <!https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
            <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.5</version>
        </dependency>
        <!-- Dependency for POI API -->
        <!-- http://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.6</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.6</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/dom4j/dom4j -->
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.1</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.3.0</version>
        </dependency>

        <!-- http://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.6</version>
        </dependency>
    </dependencies>

<build>
<plugins>
 <plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>

<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>

</configuration>
</plugin>

</plugins>

        <testResources>
            <testResource>
                <directory>src/test/resources/Properties</directory>
                <includes>
                    <include>log4j.properties</include>
                </includes>
            </testResource>
        </testResources>
    </build>
</project>

And TestNG.xml 和TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<listeners>
<listener class-name="Listeners.CustomListeners"></listener>
</listeners>
  <test name="LoginTest">
    <classes>
      <class name="TestCases.LoginTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

项目结构

Maven控制台错误

Any help is highly appreciated 任何帮助都受到高度赞赏

In your pom.xml you have this part: 在您的pom.xml您具有以下部分:

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.13.1</version>
    <scope>test</scope>
</dependency> 

You have to change the scope to compile, so it will be 您必须更改scope以进行编译,因此它将

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.13.1</version>
    <scope>compile</scope>
</dependency> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM