错误:找不到或加载主类。运行maven jar-with-dependencies

时间:2017-09-21 20:41:11

标签: java maven pom.xml

我正在使用Maven来管理个人项目,每当我尝试运行带有依赖项的jar时,我就会收到此maven错误。

$ java -jar .\SpotifyAutomation-1.0-SNAPSHOT-jar-with-dependencies.jar
Error: Could not find or load main class SpotifyRunner

(我在运行之前做了一个干净的安装)。

我的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>SpotifyAutomation</groupId>
<artifactId>SpotifyAutomation</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib</classpathPrefix>
                        <mainClass>SpotifyRunner</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.4.0</version>
    </dependency>
    <dependency>
        <groupId>se.michaelthelin.spotify</groupId>
        <artifactId>spotify-web-api-java</artifactId>
        <version>1.5.0</version>
    </dependency>
</dependencies>

有关如何修复此问题的任何见解?我试过切换我的classpathPrefix但无济于事。我的项目有一个模块和一个包。

我的项目结构如下图所示: Project Structure

0 个答案:

没有答案