当前位置: 首页 > 知识库问答 >
问题:

程序在Eclipse中运行良好,但在命令行运行Jar时引发错误[重复]

丰飞龙
2023-03-14

MVN包编译后,我尝试用java-jar app.jar运行jar,它运行了,但随后抛出了一个

共有1个答案

赫连智
2023-03-14

看起来您缺少依赖项。试着把它放在pom.xml中:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>yourpackage.YourClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

然后运行:java-jar[your-package-jar-with-dependencies.jar]

 类似资料: