我正在尝试使用maven为一个名为"logmanager"的小型家庭项目生成一个可执行jar,就像这样:
我将那里显示的代码段添加到pom.xml中,然后运行mvn assembly:assembly.它在logmanager/target中生成两个jar文件:logmanager-0.1.0.jar和logmanager-0.1.0-jar-with-dependencies.jar.当我双击第一个jar时出现错误:
Could not find the main class: com.gorkwobble.logmanager.LogManager. Program will exit.
Run Code Online (Sandbox Code Playgroud)
当我双击jar-with-dependencies.jar时出现稍微不同的错误:
Failed to load Main-Class manifest attribute from: C:\EclipseProjects\logmanager\target\logmanager-0.1.0-jar-with-dependencies.jar
Run Code Online (Sandbox Code Playgroud)
我复制并粘贴了路径和类名,并检查了POM中的拼写.我的主要类从eclipse启动配置启动.有人可以帮我弄清楚为什么我的jar文件不会运行?另外,为什么有两个罐开始?如果您需要更多信息,请与我们联系.
这是完整的pom.xml,供参考:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gorkwobble</groupId>
<artifactId>logmanager</artifactId>
<name>LogManager</name>
<version>0.1.0</version>
<description>Systematically renames specified log files on a scheduled basis. Designed to help manage MUSHClient logging and prevent long, continuous log files.</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<!-- nothing here -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.gorkwobble.logmanager.LogManager</mainClass> …Run Code Online (Sandbox Code Playgroud) 我对Maven的口头禅相对较新,但我正在尝试使用Maven构建一个命令行可运行的jar.我已经设置了我的依赖项,但是当我运行mvn install并尝试运行jar时,会发生两件事.首先,没有找到主类,这是可以纠正的.当我纠正这个问题时,我在运行时遇到错误,说明无法找到类.
Maven没有在jar中包装我的依赖库,所以我无法将jar作为独立的应用程序运行.我该如何纠正?