【问题标题】:How to build project like Eclipse Clean on Maven pom.xml如何在 Maven pom.xml 上构建像 Eclipse Clean 这样的项目
【发布时间】:2015-10-20 09:19:21
【问题描述】:

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

我做了一个自定义文件夹结构的maven项目(不遵循默认)。

结构如下:

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

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

我相信这是因为我没有在 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>

【问题讨论】:

  • 为什么不使用标准布局?!
  • @SilviuBurcea 增加可读性:(
  • 不是一个很好的理由,因为默认的 maven 布局广为人知,所以我会说这是最好的......不要使用你自己的......这会给你带来如此多的配置在 Maven 中是错误的方式。

标签: java eclipse maven testng


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    您可以使用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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 2019-02-15
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      相关资源
      最近更新 更多