【问题标题】:Java Virtual Machine Launcher : A JNI Error with SpringJava 虚拟机启动器:Spring 的 JNI 错误
【发布时间】:2015-10-25 15:13:49
【问题描述】:

我使用 Windows10 Pro 32bit ENG、EclipseEE Mars、Java 8_66。如果我想用 Spring 创建一个简单的 bean 项目并运行它,它会在 Windows 对话框中显示一个错误。当我进入这个对话框时,它产生了异常。

Java Virtual Machine Launcher - Error : 
A JNI error has occurred, please check your installation and try it again.

我在 CLASSPATH 中有:Apache *.jars

•commons-logging-1.2.jar
•commons-logging-1.2-javadoc.jar

Spring *.jars

•spring-aop-4.1.5.RELEASE.jar
•spring-beans-4.1.5.RELEASE.jar
•spring-context-4.1.5.RELEASE.jar
•spring-aspects-4.1.5.RELEASE.jar
•spring-context-support-4.1.5.RELEASE.jar
•spring-core-4.1.5.RELEASE.jar
•spring-web-4.1.5.RELEASE.jar
•spring-webmvc-4.1.5.RELEASE.jar
•spring-expression-4.1.5.RELEASE.jar

我测试过 Java 8_60 与 Spring 4.1.5、Java 8_66 与 Spring 4.1.5 或 4.2.2。

KclientMetaTest.java

package klient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import server.ServerVypis;
public class KlientMetaTest {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/Beans.xml");
        ServerVypis obj = (ServerVypis) context.getBean("mujSpring");                           //  id beanu
        obj.getMessage();   
    }
}

ServerVypis.java

package server;
public class ServerVypis {
    private String message;
    public void setMessage(String message){
        this.message = message; }
    public void getMessage(){
        System.out.println("Zde je tvuj Spring vypis  : " + message);   }
}

beans.xml 位于 /META-INF/ 文件夹中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
   <bean id="mujSpring" class="server.ServerVypis">
       <property name="message" value="Vypis z \META-INF\Bean.xml"/>
   </bean>
</beans>

控制台中显示的异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 7 more

【问题讨论】:

    标签: java eclipse spring window spring-bean


    【解决方案1】:

    我也遇到了同样的问题。

    我在 pom.xml 中做了一些更改。如果您正在使用 javax 邮件以及 aws sdk 的依赖项,请确保应在 aws sdk 之前声明 javax 邮件。

    如果您更改顺序,则会显示上述错误,因为它以错误的顺序加载 jar。因为这在我的情况下有效,希望这对您有用!

    【讨论】:

    • 通过更好地格式化您的答案来注意可读性。
    【解决方案2】:

    问题解决了。安装 Windows10 后,当我保存框架的外部 jar 时,它破坏了我对文件夹的访问。

    【讨论】:

      猜你喜欢
      • 2020-10-10
      • 1970-01-01
      • 2014-03-06
      • 2013-08-29
      • 2015-11-14
      • 1970-01-01
      • 2011-07-21
      • 1970-01-01
      • 2013-01-12
      相关资源
      最近更新 更多