无法编译maven项目

时间:2014-02-12 20:24:52

标签: eclipse maven jenkins

我正在使用maven项目(v3.1.1),我用它来进行硒自动化。我已经在Jenkins(在localhost中)托管了我的项目,并尝试从Jenkins本身编译项目。

com.eh.base
com.eh.pageobjects
com.eh.tests

[我没有使用像 src \ main \ resource ]

这样的结构

Jenkins中的maven插件将实现编译过程。我尝试使用maven插件2.2.1以及带有编译目标的3.1.1,它没有用。为了在日食层面复制这个。我尝试使用命令 mvn clean mvn compile 从命令提示符编译maven项目。

构建结果

D:\Shaw\Shaw\Projects\Branch\MyProject>mvn compile
[INFO] Scanning for projects...


[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MyProject ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Shaw\Shaw\Projects\Branch\MyProject\src\main\resources
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MyProject ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.352s
[INFO] Finished at: Thu Feb 13 01:36:23 IST 2014
[INFO] Final Memory: 10M/108M
[INFO] ------------------------------------------------------------------------

由此,我希望它能编译并生成 / target / classes 中的类文件。但这还没有这样做。由于我正在为我的项目使用自定义包,我想我应该尝试maven原型。请指教。

如果我遗漏了什么,请告诉我。

POM文件:

<?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>
    <artifactId>MyProject</artifactId>
    <groupId>com.eh</groupId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <name>MyProject</name>

    <description>A sample Maven project that demonstrates how to integrate Sauce OnDemand with WebDriver tests that run using JUnit
    </description>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-xml</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-xml.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>BaseLibrary</groupId>
            <artifactId>BaseLibrary</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/BaseLibrary.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-examples</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-examples.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-greplog</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-greplog.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-jdbc</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-jdbc.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-nblr</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-nblr.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-nbp</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-nbp.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-swing</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-swing.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-wadl</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-wadl.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-xmldog</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-xmldog.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>TestNGFileGenerator</groupId>
            <artifactId>TestNGFileGenerator</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/TestNGFileGenerator.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>jlibs</groupId>
            <artifactId>jlibs-core</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibs-core.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>SauceREST</groupId>
            <artifactId>SauceREST</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/SauceREST.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>3.0</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.33.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.github.detro.ghostdriver</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.3</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.7.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <properties>
                        :
                        <property>
                            <name>org.uncommons.reportng.escape-output</name>
                            <value>false</value>
                        </property>
                        <property>
                            <name>usedefaultlisteners</name>
                            <value>false</value>
                        </property>
                        <property>
                            <name>listener</name>
                            <value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
                        </property>
                    </properties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.14</version>
                <configuration>
                    <showSuccess>false</showSuccess>
                </configuration>
            </plugin>
             <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
            <!-- put your configurations here -->
          </configuration>
        </plugin>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                <execution>
                <phase>test</phase>
                    <configuration>
                    <tasks>
                    <zip destfile="${project.basedir}/target/surefire-reports/reports.zip"
                         basedir="${project.basedir}/target/surefire-reports/"
                         includes="**/*.html,**/*.xml,**/*.css"
                    />
                    </tasks>
                    </configuration>
                    <goals>
                    <goal>run</goal>
                    </goals>
                </execution>
                </executions>
             </plugin>

        </plugins>
    </build>


    <repositories>
        <repository>
            <id>sauce-eh</id>
            <name>sauce_quickstart</name>
            <url>file://${project.basedir}/lib</url>
        </repository>
        <repository>
            <id>java-net</id>
            <url>http://download.java.net/maven/2</url>
        </repository>
        <repository>
            <id>saucelabs-repository</id>
            <url>https://repository-saucelabs.forge.cloudbees.com/release</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

2 个答案:

答案 0 :(得分:3)

我强烈建议您关注default folder layout of Maven。这会让你的生活更轻松。

src/
├── main
│   ├── java
│   └── resources
└── test
    ├── java
    └── resources

答案 1 :(得分:0)

不建议修改Maven项目的默认文件夹结构。您似乎完全摆脱了main/srctest。我不确定您是如何,在何处或是否存储您的测试类。从长远来看,没有对代码进行测试可能代价高昂。

无论如何,如果您决定坚持使用非标准项目结构,则必须按如下方式设置源代码的路径:

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

这将告知Maven您的源代码位于src而不是src/main/java。如果您还有资源文件,例如XML或属性文件,则必须使用build/resources标记将其位置传递给Maven。