如何在Maven pom.xml上构建Eclipse Clean等项目

时间:2015-07-29 11:52:01

标签: java eclipse maven testng

我需要有关运行maven项目的帮助。我可以在Eclipse上运行该项目,我尝试在Jenkins CI上部署/运行它但没有成功。

我使用自定义文件夹结构制作了一个maven项目(不遵循默认值)。

以下是结构:

structure

我可以通过Eclipse首先清理项目来成功运行项目,我相信Eclipse会为我构建所有java文件。下面是我通过Eclipse(不是maven clean)清理项目后的'target'文件夹

enter image description here

然而,当我删除'target'文件夹的内容,并运行maven -clean和maven -install时,我收到如下错误:

enter image description here

我相信这是因为我没有在pom.xml上设置任何关于构建所有java类的内容。但是我不知道该怎么办?你能帮助我吗?现在避免改变结构。感谢

下面是pom.xml

<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>bukalapak</groupId>
<artifactId>bukalapak</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
     <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.46.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>2.46.0</version>
    </dependency>

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

<build>

<!--  <resources>
<resource>
<directory>src/bukalapak</directory>
</resource>
</resources> -->
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14.1</version>
            <configuration>
             <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
            <forkMode>never</forkMode>
                <suiteXmlFiles>
                    <suiteXmlFile>testsuite/TestSuiteBukalapak.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

</project>

2 个答案:

答案 0 :(得分:0)

您可以使用maven-compiler-plugin。例如:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

答案 1 :(得分:0)

如果您不使用默认目录结构,则必须适当地配置源目录。在您的情况下,正确的配置是:

<build>
    <sourceDirectory>src</sourceDirectory>
</build>

否则Maven会查看默认的文件夹结构。