相关疑难解决方法(0)

"无法找到或加载主类"是什么意思?

新Java开发人员遇到的一个常见问题是,他们的程序无法运行错误消息: Could not find or load main class ...

这是什么意思,是什么导致它,你应该如何解决它?

java program-entry-point class

1277
推荐指数
25
解决办法
252万
查看次数

什么是超级罐?

我正在阅读Maven文档并且遇到了'uber-jar'这个名字.

优步罐的含义是什么?它的特性/优点是什么?

uberjar maven

227
推荐指数
4
解决办法
8万
查看次数

用maven建造一个胖罐子

我有一个代码库,我想分发为jar.它还依赖于外部jar,我想在最后的jar中捆绑它.

我听说这可以用maven-assembly-plug-in,但我不明白怎么做.有人能指点我一些例子.

现在,我正在使用胖罐捆绑最后的罐子.我想用maven实现同样的目的.

jar maven maven-assembly-plugin

109
推荐指数
6
解决办法
10万
查看次数

使用Gradle构建具有依赖关系的jar

我有一个多项目构建,我在一个子项目中设置了一个任务来构建一个胖罐.我创建的任务类似于食谱中描述的任务.

jar {
  from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
  manifest { attributes 'Main-Class': 'com.benmccann.gradle.test.WebServer' }
}
Run Code Online (Sandbox Code Playgroud)

运行它会导致以下错误:

原因:您无法更改未处于未解决状态的配置!

我不确定这个错误意味着什么.我还在Gradle JIRA上报告了这个问题,以防它出现问题.

uberjar gradle

108
推荐指数
9
解决办法
12万
查看次数

如何使用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万
查看次数

尝试运行jar文件时,Manifest主要属性异常的签名文件摘要无效

我正在尝试运行我的项目的jar文件.我正在研究intelliJ并使用工件来生成jar文件.但每次我试图运行我的jar文件时它给我异常.

java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
    at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:284)
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:238)
    at java.util.jar.JarVerifier.processEntry(JarVerifier.java:316)
    at java.util.jar.JarVerifier.update(JarVerifier.java:228)
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
    at java.util.jar.JarFile.getInputStream(JarFile.java:450)
    at sun.misc.JarIndex.getJarIndex(JarIndex.java:137)
    at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:839)
    at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:831)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:830)
    at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:803)
    at sun.misc.URLClassPath$3.run(URLClassPath.java:530)
    at sun.misc.URLClassPath$3.run(URLClassPath.java:520)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:519)
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:492)
    at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
    at sun.misc.URLClassPath.getResource(URLClassPath.java:211)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:365)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Error: A JNI error has occurred, please check your installation and try again …
Run Code Online (Sandbox Code Playgroud)

java intellij-idea

30
推荐指数
6
解决办法
5万
查看次数

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

我正在编写一个嵌入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
查看次数

JCE无法在java swing应用程序中验证提供程序BC

我在JAVA中创建了一个基于swing的应用程序,它使用了一些加密技术.但是javax.crypto.KeyGenerator.getInstance("AES","BC")给出了异常:

java.security.NoSuchProviderException: JCE cannot authenticate the provider BC
        at javax.crypto.SunJCE_b.a(DashoA13*..)
        at javax.crypto.KeyGenerator.getInstance(DashoA13*..)
Run Code Online (Sandbox Code Playgroud)

那么问题是什么?

java encryption

27
推荐指数
2
解决办法
5万
查看次数

Ant:从合并的jar文件中排除文件

对于一个java项目,我想将它依赖的所有第三方jar合并到Apache Ant创建的主jar中,我已经设法做了.

问题是这些jar文件中的一些在他们的META-INF-directories中有签名文件,所以当我尝试运行我的jar文件时,我收到错误消息"Invalid signature file digest for Manifest main attributes".手动删除签名文件后,错误消失了.

我尝试使用excludes-attribute或exclude-tag 过滤我的ant文件中的签名文件,但似乎没有任何效果.

这是蚂蚁任务:

<target name="jar" description="Creates the jar file">
  <mkdir dir="${jar}"/>
  <jar destfile="${jar}/${ant.project.name}.jar" level="9" filesetmanifest="mergewithoutmain">
    <zipgroupfileset dir="${lib}" includes="*.jar"/>
    <zipfileset dir="${class}"/>
    <manifest>
      <attribute name="Main-Class" value="${mainclass}"/>
    </manifest>
  </jar>
</target>
Run Code Online (Sandbox Code Playgroud)

如何在此ant任务中过滤生成的jar中的文件?谢谢你的帮助!

ant jar

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

运行JAR时ClassNotFoundException,在IntelliJ IDEA中运行时没有错误

我刚刚开始构建Java应用程序(我确实有.NET经验),我正在尝试构建一个小型测试应用程序,其整个代码是这样的:

package com.company;

import com.microsoft.sqlserver.jdbc.SQLServerDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {

    public static void main(String[] args) throws SQLException {
        System.out.println("Buna lume!");

        SQLServerDataSource ds = new SQLServerDataSource();
        ds.setIntegratedSecurity(true);
        ds.setServerName("localhost");
        ds.setPortNumber(1433);
        ds.setDatabaseName("Test");
        Connection con = ds.getConnection();

        String SQL = "SELECT * FROM Test WHERE ID = ?";
        PreparedStatement stmt = con.prepareStatement(SQL);
        stmt.setInt(1, 2);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            System.out.println(rs.getInt(1) + ", " + rs.getString(2));
        }
        rs.close();
        stmt.close();

        con.close();
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我在IDE(IntelliJ IDEA 12.1.6社区版)中运行该应用程序,使SQL Server可用,该应用程序运行正常,它应该做到这一点. …

java jar intellij-idea sqljdbc classnotfoundexception

16
推荐指数
2
解决办法
3万
查看次数