相关疑难解决方法(0)

无法执行jar文件:"没有主要清单属性"

我已经安装了一个应用程序,当我尝试运行它时(它是一个可执行的jar)没有任何反应.当我从命令行运行它时:

java -jar"app.jar"

我收到以下消息:

"app.jar"中没有主要的清单属性

通常,如果我自己创建了程序,我会在清单文件中添加一个主类属性.但在这种情况下,由于文件来自应用程序,我不能这样做.我也尝试提取jar以查看是否可以找到主类,但是有许多类,并且它们中没有一个在其名称中包含"main"一词.必须有办法解决这个问题,因为程序在其他系统上运行正常.

java program-entry-point jar manifest

875
推荐指数
21
解决办法
125万
查看次数

使用Maven在jar中包含依赖项

有没有办法强制maven(2.0.9)在一个jar文件中包含所有依赖项?

我将一个项目构建到一个jar文件中.我希望将依赖项中的类复制到jar中.

更新:我知道我不能在jar文件中包含一个jar文件.我正在寻找一种方法来解压缩指定为依赖项的jar,并将类文件打包到我的jar中.

java maven-2 packaging jar

329
推荐指数
9
解决办法
40万
查看次数

用maven建立可执行jar?

我正在尝试使用maven为一个名为"logmanager"的小型家庭项目生成一个可执行jar,就像这样:

如何使用Maven创建具有依赖关系的可执行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)

java eclipse build-process maven-2 executable-jar

121
推荐指数
3
解决办法
15万
查看次数

如何使用Maven将所有必需的JAR文件放在最终JAR文件中的库文件夹中?

我在我的独立应用程序中使用Maven,并且我想将我的JAR文件中的所有依赖项打包到库文件夹中,如下面的答案中所述:

如何使用Maven创建具有依赖关系的可执行JAR?

我希望我的最终JAR文件有一个库文件夹,其中包含作为JAR文件的依赖项,而不是maven-shade-plugin将依赖项放在.m2文件夹中的Maven层次结构等文件夹形式的内容.

好吧,实际上当前的配置做了我想要的,但是我在运行应用程序时加载JAR文件时遇到了问题.我无法加载课程.

这是我的配置:

<plugins>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>false</overWriteSnapshots>
                    <overWriteIfNewer>true</overWriteIfNewer>
                </configuration>
            </execution>
        </executions>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>com.myapp.MainClass</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>install</id>
                <phase>install</phase>
                <goals>
                    <goal>sources</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>

</plugins>
Run Code Online (Sandbox Code Playgroud)

该项目从Eclipse运行良好,JAR文件根据我的需要放在我最终的JAR文件中的库文件夹中,但是当从目标文件夹运行最终的JAR文件时,我总是得到ClassNotFoundException:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
Caused …
Run Code Online (Sandbox Code Playgroud)

java build-process jar classloader maven

95
推荐指数
5
解决办法
19万
查看次数

用Maven 2构建一个可运行的jar

我对Maven的口头禅相对较新,但我正在尝试使用Maven构建一个命令行可运行的jar.我已经设置了我的依赖项,但是当我运行mvn install并尝试运行jar时,会发生两件事.首先,没有找到主类,这是可以纠正的.当我纠正这个问题时,我在运行时遇到错误,说明无法找到类.

Maven没有在jar中包装我的依赖库,所以我无法将jar作为独立的应用程序运行.我该如何纠正?

java build-process maven-2 executable-jar

81
推荐指数
4
解决办法
9万
查看次数

运行java -jar时无法加载Main-Class清单属性

mvn clean package按照本教程,我已经成功构建了我的Spring MVC项目.

现在我正在尝试运行该服务:

mvn clean package && java -jar target/gs-serving-web-content-0.1.0.jar
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

无法从target/gs-serving-web-content-0.1.0.jar加载Main-Class清单属性

我错过了什么吗?

java spring spring-mvc maven

57
推荐指数
2
解决办法
7万
查看次数

无法使用Jar文件查找或加载主类

我正在尝试使用加载jar

@echo off
java -jar Test.jar
pause
Run Code Online (Sandbox Code Playgroud)

随着的表现

Manifest-Version: 1.0
Main-Class: classes.TestClass
Run Code Online (Sandbox Code Playgroud)

在Jar目录中,当我提取它时,我可以清楚地看到classes\TestClass文件.

编辑:classes.TestClass确实有public static void main(String[] args).

包装减速度classes.TestClasspackage classes;

但我仍然收到错误消息

Could not find or load main class classes.TestClass
Run Code Online (Sandbox Code Playgroud)

我经历过这个问题所能找到的一切,但似乎没有任何帮助.

我已经尝试编辑类路径,重做清单,安装新的JRE.

我还应该做什么?

java program-entry-point jar class

41
推荐指数
7
解决办法
16万
查看次数

如何使用gradle kotlin脚本创建胖罐

正如标题所述,我想知道如何修改它gradle.build.kts以便创建一个独特jar的所有依赖项(包括kotlin lib)的任务.

我在Groovy中找到了这个示例:

//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
            'Implementation-Version': version,
            'Main-Class': 'com.mkyong.DateUtils'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在kotlin中写出来,除了:

task("fatJar") {

}
Run Code Online (Sandbox Code Playgroud)

kotlin build.gradle build.gradle.kts gradle-kotlin-dsl

29
推荐指数
4
解决办法
1万
查看次数

如何用maven创建基于spring的可执行jar?

我有一个基于Maven的Spring-WS客户端项目,我想打包成一个jar.在eclipse中,一切都运行正常.当我尝试将其打包为可执行jar时,我得到ClassNotFound异常,因为Spring jar没有包含在我的应用程序jar中.

所以我添加了maven-shade-plugin来包含我的应用程序jar中的所有依赖项.当我查看我的app jar时,我看到包含所有依赖项的所有类文件(所有库jar都被爆炸).

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.cws.cs.Client</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

我的问题是在打包过程中,我的多个spring依赖项有不同的META-INF/spring.schemas文件相互覆盖.因此,我的最后一个jar有一个不完整的spring.schemas文件.

因此,当我尝试运行我的可执行jar时,我收到Spring错误消息,因为spring.schemas文件不完整(Spring-WS的jar覆盖了Spring-core的spring.schemas文件),因此无法找到文件.

我的可执行jar的META-INF/spring.schemas:

http\://www.springframework.org/schema/web-services/web-services-1.5.xsd=/org/springframework/ws/config/web-services-1.5.xsd
http\://www.springframework.org/schema/web-services/web-services-2.0.xsd=/org/springframework/ws/config/web-services-2.0.xsd
http\://www.springframework.org/schema/web-services/web-services.xsd=/org/springframework/ws/config/web-services-2.0.xsd
Run Code Online (Sandbox Code Playgroud)

而不是Spring-beans.jar META-INF/spring.schemas:

http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
Run Code Online (Sandbox Code Playgroud)

我很难过.我不确定是否/如何将所有内容打包为单个可执行jar.我不知道这是一个阴影插件配置问题,还是我试图做一些不可能的事情.我不得不手动创建自己的spring.schemas文件(其他的串联)似乎是不正确的.

我可能有点跳了一下枪.在挖掘插件的更多信息时,我注意到我之前错过的AppendingTransformer.但是,我关心的是如何知道哪些其他文件有同样的问题?我发现/抓住了这个特殊的Spring问题.我不知道任何其他可能正在做类似事情的库......

任何建议,将不胜感激.

java spring spring-ws maven maven-shade-plugin

28
推荐指数
3
解决办法
4万
查看次数

只有当依赖性组装成一个罐子时才会抛出泽西异常

我正在编写一个嵌入Jetty w/Jersey的服务器.当我从Eclipse执行时,一切都很棒.但是,如果我使用Maven的程序集将我的服务器和所有依赖项组装到一个jar中:单个目标,我会得到一个例外:

Sep 26, 2012 5:35:59 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java class com.acme.server.webservice.
exception.WebServiceFailure, and Java type class com.acme.server.webserv
ice.exception.WebServiceFailure, and MIME media type application/json was not fo
und
Sep 26, 2012 5:35:59 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media type
are:
*/* ->
  com.sun.jersey.server.impl.template.ViewableMessageBodyWriter

17:35:59.372 [qtp184245201-22 - /] ERROR o.a.h.ReflectorServletProcessor - onReq
uest()
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A mess
age body writer for Java class com.acme.server.webservice.exception.WebS
erviceFailure, and Java …
Run Code Online (Sandbox Code Playgroud)

java jar jersey executable-jar maven

27
推荐指数
1
解决办法
6142
查看次数