【问题标题】:Not able to run java main method using maven [duplicate]无法使用maven运行java main方法[重复]
【发布时间】:2017-01-30 02:03:15
【问题描述】:

在运行 java 代码时获取错误类未找到异常 包名是 com.personal.cucumber.Maven_Try 类名是 Try_Class

POM 附在下面,注意 JDK 是在 Java 编译器中设置的

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.personal.cucumber</groupId>
<artifactId>Maven_Try</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Maven_Try</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.personal.cucumber.Maven_Try.Try_Class</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>../conf/</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

  • 你实际启动的是什么命令?您的源代码树看起来如何?如果您打开 jar,它是否包含该类?

标签: java maven pom.xml


【解决方案1】:

如果你遇到 错误:无法使用 maven 运行 java main 方法 这样做对我有用: 错误原因:这个错误的原因是运行maven项目的jar文件或依赖没有正确安装。

错误解决方法:进入项目文件夹(例如:D:\office\OIA-service-app) 在计算机的地址栏中键入命令“cmd”,然后按 Enter。 在命令提示符下键入命令“mvn clean install”[image][1] 确保您有互联网连接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2023-02-10
    • 2015-12-27
    • 2015-10-18
    • 2012-01-02
    相关资源
    最近更新 更多