Executing java class in correct directory - java

I cannot seem to run my java program because it thinks my MO.class file is in the classpath for my gson library. What am I doing wrong?
$ lsgson MO.java
$ javac -cp .:gson/gson/target/gson-2.7.1-SNAPSHOT.jar MO.java
$ java -cp .:gson/gson/target/gson-2.7.1-SNAPSHOT.jar MO
Exception in thread "main" java.lang.NoClassDefFoundError: MO (wrong name: com/google/gson/MO)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

Removed the package com.google.gson from my MO.java file.

Related

Unable to create Model Class from Adempiere Class

I have this table C_InvoiceTaxDetail and I am trying to create a model class with the name of MInvoiceTaxDetail.
Now i have created the class , placed it in org.compiere.model and extended X_C_InvoiceTaxDetail class also.
But Still aftersave method works only if i place it in X_C_InvoiceTaxDetail and if i place it in MInvoiceTaxDetail gives the following error:
===========> GridTable.dataSave: Persistency Issue - C_INVOICETAX_DETAIL: org/compiere/model/MINVOICETAXDETAIL (wrong name: org/compiere/model/MInvoiceTaxDetail) [20]
java.lang.NoClassDefFoundError: org/compiere/model/MINVOICETAXDETAIL (wrong name: org/compiere/model/MInvoiceTaxDetail)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at org.compiere.model.MTable.getPOclass(MTable.java:360)
at org.compiere.model.MTable.getClass(MTable.java:300)
at org.compiere.model.MTable.getPO(MTable.java:537)
at org.compiere.model.GridTable.dataSavePO(GridTable.java:2049)
at org.compiere.model.GridTable.dataSave(GridTable.java:1467)
at org.compiere.model.GridTab.dataSave(GridTab.java:983)
at org.compiere.apps.APanel.cmd_save(APanel.java:2045)
at org.compiere.apps.APanel.actionPerformed(APanel.java:1708)
at org.compiere.apps.AppsAction.actionPerformed(AppsAction.java:286)
Make sure you run the Generate Model utility after adding the new Class. You can find full details in the link to the Adempiere wiki.

Maven: compiling using jar file from system

I am working on a maven project for which I am using a custom jar file and I included that in pom.xml as
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-migrations</artifactId>
<scope>system</scope>
<version>0.7.0</version>
<systemPath>${basedir}/dropwizard-migrations-0.7.0.jar</systemPath>
</dependency>
but after mvn package and Compiling I am getting the NoClassDefFoundError
Exception in thread "main" java.lang.NoClassDefFoundError: io/dropwizard/migrations/MigrationsBundle
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at in.myGroupID.Artifact.game.myApplication.initialize(myApplication.java:48)
at io.dropwizard.Application.run(Application.java:70)
at in.myGroupID.Artifact.game.myApplication.main(myApplication.java:44)
Caused by: java.lang.ClassNotFoundException: io.dropwizard.migrations.MigrationsBundle
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 15 more
I think everything is all right in your case. But please make sure that the location of your jar is correct. I mean in ${basedir}/dropwizard-migrations-0.7.0.jar ${baseDir} means project home directory and your jar must be in your project home directory . If it is not in project home directory, put it there or change systemPath value to point actual location to the jar file.

Exception in java.lang.securityexception

I am getting this exception when i am trying to run a simple class from intellijIdea using spark
Exception in thread "Thread-0" java.lang.SecurityException: class "javax.servlet.SessionTrackingMode"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:952)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:666)
at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at spark.webserver.SparkServerFactory.create(SparkServerFactory.java:33)
at spark.Spark$1.run(Spark.java:303)
at java.lang.Thread.run(Thread.java:744)

java.lang.NoClassDefFoundError: javax/servlet/http/HttpSessionBindingListener

Don't know how this was working earlier, but I guess I am doing something wrong with my libraries in my web app on tomcat.
It is when I am trying to run a class, from a project deployed on tomcat, I am getting following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpSessionBindingListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpSessionBindingListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
Please help.
jar containing javax/servlet/http/HttpSessionBindingListener is missing.so download this jar
and then set your classpath

Active MQ - HelloWorld example exception

I'm trying to run the hello world example found here
I added activemq-all-5.5.1.jar to the libraries already
It builds successfully with the following warning
warning: [options] bootstrap class path not set in conjunction with -source 1.6
But it doesn't run, I get this exception
Exception in thread "Thread-0" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/jms/JMSException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at hw_testing.HW_testing$HelloWorldProducer.run(HW_testing.java:69)
at java.lang.Thread.run(Thread.java:722)
Exception in thread "Thread-1" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/jms/JMSException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at hw_testing.HW_testing$HelloWorldProducer.run(HW_testing.java:69)
at java.lang.Thread.run(Thread.java:722)
...
And the same exception for thread 3 and 4
Can anybody help me with that please?
This is a problem with dependencies (javax/jms/JMSException is in multiple jars), which occurs e.g. with javaee-api (5 or 6) - this jar lacks some method bodies for several classes. activemq-all-5.5.1.jar also contains javax.jms.JMSException but these classes are not identical. If javaee-api comes first in classpath, you will get the java.lang.ClassFormatError.
If you use maven, put javaee-api after activemq-all (or remove it). In general, remove unecessary dependencies.

Categories