Java 虚拟机启动器:Spring 的 JNI 错误

Java Virtual Machine Launcher : A JNI Error with Spring

我使用 Windows10 Pro 32 位 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 vs Spring 4.1.5,Java 8_66 vs Spring 4.1.5 或 4.2 .2.

KlientMetaTest.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

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

我遇到了同样的问题。

我对 pom.xml 进行了一些更改。如果您正在使用 javax mail 以及 aws sdk 的依赖项,那么请确保 javax mail 应该在 aws sdk 之前声明。

如果您更改顺序,那么它会显示上述错误,因为它加载错误的 jars sequence.As 这适用于我的情况,希望这对您有用!