使用IntelliJ构建工件总是使用错误的主类(导致无效或损坏的JAR文件)

时间:2014-11-28 15:02:13

标签: java maven intellij-idea jar automation

我有一个像这样的项目

enter image description here

我有一个主类和一个测试类。 Test类有一个main()方法。在MANIFEST中,我还设置了主类是测试类,我也为pom文件设置了相同的值。但每当我构建工件时,它总是说无效或损坏的jar文件。我查看了JAR文件,它始终从主要的类中获取,即使我做了所有设置。

我的代码如下:

主要课程:

package com.autodesk.internal.domain;

public class InternalAutodesk {

private static final String INTERNAL_AUTODESK_PASSWORD_KEY = "INTERNAL_AUTODESK_PASSWORD";
private static final String INTERNAL_AUTODESK_USERNAME_KEY = "INTERNAL_AUTODESK_USERNAME";

public final String password;
public final String username;
public final String internal_url;

public InternalAutodesk(){
    username = System.getProperty(INTERNAL_AUTODESK_USERNAME_KEY, "xxx");
    password = System.getProperty(INTERNAL_AUTODESK_PASSWORD_KEY, "xxx");
    internal_url = System.getProperty("INTERNAL_AUTODESK_URL_KEY", "xxx");
}

}

测试类:(省略所有导入和普通代码以便于阅读)

package com.autodesk.internal.login;   

public class InternalLoginTests{

public static WebDriver driver;
public static WebDriverWait waitForDriver;

@BeforeClass
public static void createWebDriver()
{
    //invoke a driver and wait for a driver
    driver = new FirefoxDriver();        

    waitForDriver = new WebDriverWait(driver, 60);

}

@Test
public void testScenarioTestCase()
{        
    loginStaging();
    sortToggle();
    clickModel();
}

public void loginStaging()
{
    //code here
}

public void clickModel()
{
    //code here
}

public void sortToggle()
{
   //code here
}

@AfterClass
public static void quitWebDriver()
{
    driver.quit();
}

public static void main(String[] args)
{        
    TestSuite suite = new TestSuite(InternalLoginTests.class);
    TestResult result = new TestResult();
    suite.run(result);
}

}

和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>

<groupId>autodesk</groupId>
<artifactId>autodesk</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <env.config>local</env.config>
    <browser>firefox</browser>
    <threads>1</threads>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
    <sourceDirectory>${project.basedir}/src/test/java</sourceDirectory>
    <remote>false</remote>
    <seleniumGridURL/>
    <platform/>
    <browserVersion/>
</properties>

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>2.44.0</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>com.opera</groupId>
                <artifactId>operadriver</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.44.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<profiles>
    <profile>
        <id>selenium-tests</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>com.autodesk.internal.login.InternalLoginTests</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>com.autodesk.internal.login.InternalLoginTests</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                    <version>2.3.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.7.2</version>
                    <configuration>
                        <testSourceDirectory>${project.basedir}/src/test/java/</testSourceDirectory>
                        <testClassesDirectory>${project.build.directory}/test-classes/</testClassesDirectory>
                        <includes>
                            <include>**/*WebDriver.java</include>
                            <include>**/*Tests.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/Abstract*.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

我指出了主类在测试类中的所有位置,但它始终从main中获取另一个。这是它应该的样子吗?

0 个答案:

没有答案