有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java是我的pom。xml安装和生成失败

这是我的pom。用于java项目的xml文件,该项目使用selenium创建一组测试

<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>TestMach</groupId>
    <artifactId>TestMach</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MainTestMach</name>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>main.ExtractMain</mainClass>
                <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                </arguments>
            </configuration>
        </plugin>

        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.3-1100-jdbc4</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>2.47.1</version>
        </dependency>

        <dependency>
            <groupId>com.opera</groupId>
            <artifactId>operadriver</artifactId>
        </dependency>

        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.9</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.3</version>
        </dependency>
    </dependencies>     
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.opera</groupId>
                <artifactId>operadriver</artifactId>
                <version>1.5</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-remote-driver</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

当我构建它时,会出现以下错误:

LF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3:java (default-cli) on project TestMach: An exception occured while executing the Java class. null: InvocationTargetException: org/openqa/selenium/WebDriver : Unsupported major.minor version 51.0 -> [Help 1]

共 (2) 个答案

  1. # 1 楼答案

    使用Java7或更高版本构建,第二个问题应该得到解决

    根据您的错误,类org.openqa.selenium.WebDriver具有类版本51.0,这表明它是为目标版本Java 7构建的。由于您使用的是Java 6,因此加载该类失败。因此,升级Java将修复InvocationTargetException

  2. # 2 楼答案

    至于SLF4J中的错误,实际上可以检查它提到的URL(http://www.slf4j.org/codes.html#StaticLoggerBinder

    至于运行应用程序时的错误,错误如下

    org/openqa/selenium/WebDriver : Unsupported major.minor version 51.0
    

    似乎错误发生在Selenium尝试加载firefox驱动程序时,因为Selenium firefox驱动程序版本2.47.1是使用java版本7构建的

    尝试使用更高的java版本运行应用程序,以使用jdk版本7,或者尝试安装旧版本的firefox驱动程序