Java Virtual Machine Launcher : A JNI Error with Spring - java

I use Windows10 Pro 32bit ENG, EclipseEE Mars, Java 8_66. If I want create a easy bean project with Spring and run it it show me a error in Windows dialog. When I enter this dialog it generated exception.
Java Virtual Machine Launcher - Error :
A JNI error has occurred, please check your installation and try it again.
I have in 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
I have the tested Java 8_60 vs Spring 4.1.5, Java 8_66 vs Spring 4.1.5 or 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 which is in /META-INF/ folder
<?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 which was showing in console :
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

I have faced the same problem.
I made some changes in my pom.xml. Ff you are using the dependency of javax mail as well aws sdk then make sure that javax mail should be declare before the aws sdk's.
If you change the sequence then it will show the above error as it's loading jars in wrong sequence.As this worked in mine case, Hope this will work for you!

Problem solved. After I install Windows10, it broke my access to folders when I have save the external jars of frameworks.

Related

"Getting started" issue with JOSS JavaSWIFT

I'm testing joss javaswift following this link. I also added JAR files from here to my project. But it provides an error. What am I doing wrong?
package test;
import org.javaswift.joss.client.factory.AccountConfig;
import org.javaswift.joss.client.factory.AccountFactory;
import org.javaswift.joss.model.Account;
public class Test {
public static void main(String[] args)
{
String username = "user";
String password = "pwd";
String authUrl = "http://...";
String tenantName = "test";
AccountConfig config = new AccountConfig();
config.setUsername(username);
config.setPassword(password);
config.setAuthUrl(authUrl);
config.setTenantName(tenantName);
Account account = new AccountFactory(config).createAccount();
}
}
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/http/conn/scheme/SchemeSocketFactory at
org.javaswift.joss.client.factory.AccountFactory.createClientImpl(AccountFactory.java:38)
at
org.javaswift.joss.client.factory.AccountFactory.createAccount(AccountFactory.java:28)
at test.TestSWIFT3.main(TestSWIFT3.java:23)
Caused by: java.lang.ClassNotFoundException:
org.apache.http.conn.scheme.SchemeSocketFactory at
java.net.URLClassLoader$1.run(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) 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) ... 3 more
I think that you have a problem with the dependencies of the project.
Generally speaking, you need to create a project and in the project create a pom file for download the dependencies dynamically using maven.
The structure of the project should have a pom.xml file in the general configuration.
The pom file should contain at minimum the next information.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>testJoss</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.javaswift</groupId>
<artifactId>joss</artifactId>
<version>0.9.7</version>
</dependency>
</dependencies>
</project>
The first line is the definition required for the pom in the project.
I create an example project with the proper libraries.
https://bitbucket.org/stackoverflowquestion/testjoss/src/b6f930cd02d85ec71c27d5560ca2fe34097ce4d4?at=master
The example project works fine and the issue with the libraries is not present. The example have the debug activated, so, it is possible to see if everything goes well.

Using maven ant plugin in javafx application, How to add Dependencies in javaFX jar. Still facing class not found exception

I using this guide added my dependencies to main jar JavaFX jar with dependencies bundled
i am facing dependencies issue which causing Class not found exception. My Pom is exactly like mentioned in above link. i use dependencies plugin to copy dependencies to lib folder in target.
Here is my stack trace
Try calling Class.forName(com.client.main.App) using classLoader = j
ava.net.URLClassLoader#3c9076d
found class: class com.client.main.App
launchApp: Try calling com.sun.javafx.application.LauncherImpl.launchApplication
Autoconfig of proxy is completed.
JavaFX: using com.sun.javafx.tk.quantum.QuantumToolkit
Exception in Application init method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.javafx.main.Main.launchApp(Main.java:698)
at com.javafx.main.Main.main(Main.java:871)
Caused by: java.lang.RuntimeException: Exception in Application init method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown So
urce)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/Module
at com.nuaxis.rpas.client.main.App.init(App.java:25)
... 4 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.Module
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
Done with invoke and wait
Maven Ant Task in maven pom file using maven ant plugin
<jfxjar destfile="${project.build.directory}/${project.build.finalName}">
<fileset dir="${project.build.directory}/classes" />
<fileset dir="${project.build.directory}/lib/" includes="*.jar" />
<application name="${project.name}" mainClass="com.client.main.App" />
<resources>
<fileset dir="${project.build.directory}/lib/" includes="*.jar" />
</resources>
</jfxjar>
Here is my Fx Application Class code
public class App extends Application {
/*public static Logger mLogger = LoggerFactory.getLogger(App.class); */
public static Injector injector;
public static AppHandler mAppHandler;
#Override
public void init() throws Exception {
// TODO Auto-generated method stub
super.init();
injector = Guice.createInjector(new GuiceModule());/*This line cause exception*/
mAppHandler = injector.getInstance(AppHandler.class);
if(mAppHandler!=null)
mAppHandler.startHandler();
}
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/FXMLDocument.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/style.css");
stage.setTitle("RPAS Java Client");
stage.getIcons().add(new Image("/images/RPAS Java Client.png"));
stage.setScene(scene);
stage.show();
}
#Override
public void stop() throws Exception {
mAppHandler.stopHandler();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Here is my understanding
Now what i understand is my dependencies are not properly loading. ant "jar making" task makes jar without any issues. when i double click it through exception. I opened the jar and here is my Manifest
Manifest-Version: 1.0
JavaFX-Version: 2.2
JavaFX-Application-Class: com.client.main.App
JavaFX-Class-Path: guice-3.0.jar hamcrest-core-1.3.jar javax.inject-1.jar log4j-1.2.15.jar slf4j-api-1.7.7.jar slf4j-log4j12-1.7.7.jar
Created-By: JavaFX Packager
Main-Class: com/javafx/main/Main
I also wonder when i saw that jar making process add com.javafx.main.Main.java file to the code automatically which first check Run time(JRE and FX) and then if all successful invoke the com.sun.javafx.Application.LauncherImp .
can any body help me?
I had resolved the issue. see my final pom at this link where should i put installer resources (wxs file,dmg-script,icon) and how to configure maven antrun when deploying self contained app

Throwing Error Running slf4j-api through Maven

Entry in my porm.xml for slf4j
enter code here
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>compile</scope>
</dependency>
score code:
package test.test1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
//System.out.println( "Hello World!" );
Logger logger = LoggerFactory.getLogger("App.class");
logger.info("Test");
}
}
Compiling is successful through Maven, but during Running Exception is thrown.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFacto
ry at test.test1.App.main(App.java:14)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 1 more
Should set the classpath manually for slf4j jar file??
Maven picks up the dependencies you defined in the pom.xml from your local repository so everything compiles fine. However when you launch the application from a script or commandline you need to specify where the necessary classes are found, through the classpath.
For eclipse, there's the m2e & m2e-wtp plugins which integrate maven with your IDE so you don't need to add the jars manually one by one. Instead you'll have a sort of "virtual maven library" which contains references to all your dependencies, like in the image below:

Spring can't find configuration in path

well I'm runnning this code and it cant' find the springconfig4.xml file:
package com.nortal.pirs.test.independant;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test4 {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/com/nortal/pirs/beans/springconfig4.xml");
BeanFactory factory = context;
Test3 instance = (Test3) factory.getBean("Test3");
instance.run();
}
}
I mean I was kind of expecting it not to work, because in Java it never works when you try to use a path that is not in your current package. However as many Spring tutorials I've seen, they all show this way of specifying the configuration file.
Now my springconfig4.xml is in my applications' src/com/nortal/pirs/beans folder. So how do I specify it so that it can be found here?
The current Test4 class is located in src/com/nortal/pirs/test/independant folder.
My stacktrace:
2012-12-09 06:16:15,734 [main] INFO org.springframework.context.support.AbstractApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#b24044e: startup date [Sun Dec 09 06:16:15 EET 2012]; root of context hierarchy
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:121)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:168)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:167)
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:195)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:128)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.nortal.pirs.test.independant.Test4.main(Test4.java:9)
Caused by: java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 10 more
My springconfig4.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.nortal.pirs.businesslogic.logic"></context:component-scan>
<context:component-scan base-package="com.nortal.pirs.test.independant"></context:component-scan>
</beans>
Or is the problem somewhere else maybe?
Your stacktrace points this:
java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
You need to download the spring-asm-3.1.2.RELEASE.jar file from the maven repo (supposing that you are using spring 3.1.2) or if you are using maven, edit your pom.xml file and add the next lines:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
Also, this line:
ApplicationContext context = new ClassPathXmlApplicationContext("/com/nortal/pirs/beans/springconfig4.xml");
Has an error, the path must not start with a trailing /., so the path to the file becomes: "com/nortal/pirs/beans/springconfig4.xml".
The ClassPathResource javadoc states that it will be removed anyways:
Create a new ClassPathResource for ClassLoader usage. A leading slash
will be removed, as the ClassLoader resource access methods will not
accept it.
Exception says it is not finding a class, not Spring context xml
Caused by: java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
please add asm dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.asm</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
Add spring-asm-3.0.1.RELEASE.jar and spring-expression-3.0.1.RELEASE.jar.
java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
Just add the spring-asm-3.1.2.RELEASE.jar file. Place it in your lib folder.
For the above problem as mentioned above these jars are missing namely 1.org.springframework.asm-3.0.1.RELEASE-A.jar
2.org.springframework.expression-3.0.1.RELEASE-A.jar
or
Add all the core Jars of Spring so that any new programmer can Run all basic level programs.
There is no need of below line in your program. insted of that you can use context insted of factory in the above program.
BeanFactory factory = context
We usually use ApplicationContext insted of BeanFactory.
Even if you use BeanFactory there will be no effect for the program.
Add the Jars which is shown in the Screen short and it will work

Cannot find the main class after converting java project to maven

I have a very simple HelloWorld code in Java which works ok. I'm using Eclipse and trying to figure out how to import dependencies for a project with the maven2 eclipse plugin.
public class testMavenDep {
public static void main(String arg[]){
System.out.println("Hello World");
}
}
However, when I right click on the project > configure > convert to maven project, and then try and run it gives me an error message saying...
Could not find the main class: testMavenDep.testMavenDep. Program will exit.
And the following in the console...
java.lang.NoClassDefFoundError: testMavenDep/testMavenDep
Caused by: java.lang.ClassNotFoundException: testMavenDep.testMavenDep
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
Exception in thread "main"
My pom file is...
<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/xsd/maven- 4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testMavenDep</groupId>
<artifactId>testMavenDep</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
My question is, for an already existing Java Project, what is the proper way to add maven dependencies? I can add the dependencies using the above method but I'm getting issues with it losing track of the main class. Thanks in advance!
What is the source folder that you are putting your main class in? By default, Eclipse puts it in src, but maven conventions are src/main/java. It could be that adding maven dependencies is changing your source folders so that your class is not compiled.

Categories