Weka DiscriminantAnalysis NoClassDefFoundError - java

I'm trying to use MultiClassFLDA in discriminant analysis package but I always get an error on running the code and defining a new instance of the MultiClassFLDA class
Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Vector
at assignment2.face.tryLDA(face.java:141)
at assignment2.Assignment2.main(Assignment2.java:106)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Vector
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
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)

It seems to be linked to some dynamic class loading in newer versions of Weka, presumably within the Weka Package Manager: that class is defined in the mtj.jar, which is bundled inside weka.jar. In that other question, an answer suggested to extract the mtj.jar and add it to your classpath.
As I didn't have this problem with other Filters, my guess is that MultiClassFLDA is not implemented correctly: I found out is that if you use another Filter before, that specific class will get loaded:
// Run a dummy Filter for correct initialization
Filter f = new Standardize();
f.setInputFormat(data);
Filter.useFilter(new Instances("", params, 0), f); // Dummy run on empty dataset
// Now run the MultiClassFLDA
f = new MultiClassFLDA();
f.setInputFormat(data);
data = Filter.useFilter(data, f);
N.B. that is a really ugly hack! I used it to be able to work. I'll edit my answer when I find the appropriate way to do it (other than extracting the jar from Weka itslef).

Related

(java string concatenation)How come this is giving this exception?

this is my simple code.
class atmPin{
public static void main(String[] args) {
int x = 0;
System.out.println("hi there"+x);
}
}
When i run it i get this exception errors.
java atmPin
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
at atmPin.main(atmPin.java:6)
Caused by: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
... 1 more
Caused by: java.lang.ClassNotFoundException: java.lang.invoke.StringConcatFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
is this something to do with java version? i have no idea why is it happening. this is such a simple thing. :(
getting the same kind of exception even with strings.
eg.
String x = "";
x += "a";
java.lang.invoke.StringConcatFactory is a class which appeared in Java 9 in order to implement JEP 280 (Indify String Concatenation) which changes behaviour of javac compiler so that it uses invokedynamic instructon together with the given class for string concatentaion. So the reason for this error most probably is compiling using javac from JDK 9 or later while running this code under Java 8 or less (or, with much less chance, using custom java runtime).
In order to solve it another version of compiler might be used or another version may be specified to the compiler or another JRE should be used for running the compiled class(es).

Apache Velocity 2.0 Scripting Compilable not working

I'm trying to check velocity scripting engine 2.0 which Provide JSR 223 implementation and support of Compilable
the Compilable interface has been implemented in the process.
I use jars: velocity-engine-scripting-2.0.jar, velocity-1.7.jar, commons-collections-3.2.2.jar
from previous answer I use the following code
//class org.apache.velocity.script.VelocityScriptEngine
final ScriptEngine engine = engineFactory.getScriptEngine();
if (engine instanceof Compilable) {
try {
((Compilable) engine).compile("");
...
For velocity I get the following:
javax.script.ScriptException: org.apache.velocity.exception.ResourceNotFoundException: No template name provided
at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:311)
at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:288)
at com.Workers.LevelCheck.main(LevelCheck.java:69)
Caused by: org.apache.velocity.exception.ResourceNotFoundException: No template name provided
at org.apache.velocity.runtime.resource.loader.StringResourceLoader.getResourceStream(StringResourceLoader.java:353)
at org.apache.velocity.Template.process(Template.java:108)
at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:306)
... 2 more
Also when I tried to give template name ((Compilable) engine).compile("v.vm"); it failed with same exception
You cannot use velocity-engine-scripting-2.0.jar with velocity-1.7.jar, you need to use velocity-engine-core-2.0.jar otherwise you'll get unpredictable results.

Java 7u55 Eclipse System Fragment Classloader

In previous versions of Java I was able to use a fragment that had a host of system-bundle in order to provide classes to the boot classloader.
In my particular case this was to support using Jacorb in Eclipse. This all worked fine prior to Java 7u55.
I created an osgi fragment that contained all the jars for Jacorb. The manifest looks like this:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.jacorb.systemFragment
Bundle-SymbolicName: org.jacorb.systemFragment
Bundle-Version: 3.3.0.20140422-1108
Bundle-ClassPath: jars/slf4j-jdk14-1.6.4.jar,
jars/slf4j-api-1.6.4.jar,
jars/jacorb-3.3.jar
Fragment-Host: system.bundle; extension:=framework
Export-Package: org.jacorb.config;version="3.3.0", ....
I also specify the following as vm args:
-Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB
-Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton
-Dorg.omg.PortableInterceptor.ORBInitializerClass.standard_init=org.jacorb.orb.standardInterceptors.IORInterceptorInitializer
When I ran my Eclipse application in Java 7u51 I am able to call ORB.init() successfully.
When I run the same application in Java 7u55 I get the following:
Caused by: java.lang.ClassNotFoundException: org.jacorb.orb.ORBSingleton
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.omg.CORBA.ORB.create_impl_with_systemclassloader(ORB.java:306)
If I add the following as vmargs it works.
-Djava.endorsed.dirs=${jacorb/lib}
I confirmed that this effects Java 7u55 Java 6u30 and Java 8u5
I didn't need to do this before. Any ideas why?
--- EDIT 04/30 ---
Did some more digging and I found a commit to ORB.java that is causing the issue.
changeset: 817:a8d27c3fc4e4
tag: jdk7u55-b05
user: msheppar
date: Tue Jan 21 12:46:58 2014 +0000
summary: 8025005: Enhance CORBA initializations
This commit changed the way the ORB class was created. Instead of using the Thread context class loader it is now hard coded to use the SystemClassLoader.
- singleton = create_impl(className);
+ singleton = create_impl_with_systemclassloader(className);
}
}
return singleton;
}
+ private static ORB create_impl_with_systemclassloader(String className) {
+
+ try {
+ ReflectUtil.checkPackageAccess(className);
+ ClassLoader cl = ClassLoader.getSystemClassLoader();
+ Class<org.omg.CORBA.ORB> orbBaseClass = org.omg.CORBA.ORB.class;
+ Class<?> singletonOrbClass = Class.forName(className, true, cl).asSubclass(orbBaseClass);
+ return (ORB)singletonOrbClass.newInstance();
+ } catch (Throwable ex) {
+ SystemException systemException = new INITIALIZE(
+ "can't instantiate default ORB implementation " + className);
+ systemException.initCause(ex);
+ throw systemException;
+ }
+ }
I've tried to log a ticket to Orcale about this problem. In the mean time, is there a way to override the ORB.java that comes with the JVM via some sort of fragment?
I have the same problem (and I saw many others having it too) but with a CORBA based Webstart application.
The problem of this change is that the SystemClassLoader which is forced to be used due to the change in u55 doesn't know how to load the ORB & ORBSingleton classes specified through the mentioned properties as they are part of the application classpath - in my case loaded by JNLPClassloader.
I guess there is a similar constalation in your case.
One way to replace the JDK version of orb.omg.CORBA you've used already by specifying -Djava.endorsed.dirs=${jacorb/lib/}. This replaces JDK's org.omg.CORBA package version with the one provided by JacORB which uses the ContextClassLoader of the current Thread instead (the same as the pre u55 code has done).
Another option is to use e.g. -Xbootclasspath/p:${jacorb/lib/jar-containing-omg-api.jar} or copy the JARs containing JacORB's version of org.omg.CORBA to <jre-home>/lib/endorsed.
Unfortuantelly this doesn't helped for my Webstart application problem.
Do you need the system-wide/singleton ORB to be the Jacorb ORB? If not then the simplest solution here might be to just drop -Dorg.omg.CORBA.ORBSingletonClass from the command line. Remember the singleton ORB is just the TypeCode factory, your call to the 2-arg ORG.init will still give a Jacorb ORB because you have org.omg.CORBA.ORBClass set to select it.
The (recently updated, as this information wasn' there before) release notes mentioned by user3054250 (thank you for this) point to another possible workaround.
Specifying only the ORB property but omiting ORBSingleton works (short test) in my CORBA/Webstart application together with JacORB 3.4.
It doesn't work with OpenORB (as OpenORB checks for the "right" instance of ORBSingleton) so I have to upgrade my application to JacORB but it is a solution.

NoClassDefFound error using Jode obfuscator

I'm using jode's obfuscator in an attempt to obfuscate all of the class files in my jar. I've packaged all the class files in the jar, so that I can use the config to specify what I need loading, and what I need preserving.
Here is my package hierarchy:
src
src.loading
src.loading.org
src.loading.sign
Here's what I've specified as my wildcards:
load = new WildCard { value = "src.*" }
preserve = new WildCard { value = "src.loading.org.*" }
And this is the error I get (Decompiling too. It's the only class.)
C:\Users\Kieran\Desktop\jode>java jode.obfuscator.Main project.jos
Jode (c) 1998-2001 Jochen Hoenicke <jochen#gnu.org>
used before: 479080
Loading and preserving classes
Exception in thread "main" java.lang.NoClassDefFoundError: src.loading.Class48
at jode.bytecode.ClassInfo.loadInfo(ClassInfo.java:631)
at jode.obfuscator.ClassIdentifier.initClass(ClassIdentifier.java:371)
Exception while decompiling:java.lang.NoClassDefFoundError: src.loading.Class48
at jode.bytecode.ClassInfo.loadInfo(ClassInfo.java:631)
at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:86)
at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:123)
at jode.decompiler.Decompiler.decompile(Decompiler.java:191)
at jode.swingui.Main.run(Main.java:204)
at java.lang.Thread.run(Unknown Source)
The class does exist, and I the jar file is fully functional. Why am I getting this error?
This specific class is using reflection, to access java.lang.Runtime, could this be the issue...?

No Such method error during transformation to pdf in Java

I have a problem while transforming the xslt to pdf in java, i am following the same process posted in this link
"Java Transformation to PDF".
Error:
`
Caused by: java.lang.NoSuchMethodError: org.apache.xmlgraphics.java2d.GraphicContext.<init>(Lorg/apache/xmlgraphics/java2d/GraphicContext;)V
at org.apache.fop.render.intermediate.IFGraphicContext.<init>(IFGraphicContext.java:50)
at org.apache.fop.render.intermediate.IFGraphicContext.clone(IFGraphicContext.java:56)
at org.apache.fop.render.intermediate.IFRenderer.saveGraphicsState(IFRenderer.java:632)
at org.apache.fop.render.intermediate.IFRenderer.startViewport(IFRenderer.java:885)
at org.apache.fop.render.intermediate.IFRenderer.startVParea(IFRenderer.java:878)
at org.apache.fop.render.AbstractRenderer.renderRegionViewport(AbstractRenderer.java:289)
at org.apache.fop.render.intermediate.IFRenderer.renderRegionViewport(IFRenderer.java:731)
at org.apache.fop.render.AbstractRenderer.renderPageAreas(AbstractRenderer.java:249)
at org.apache.fop.render.AbstractRenderer.renderPage(AbstractRenderer.java:230)
at org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:580)
at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:114)
at org.apache.fop.layoutmgr.AbstractPageSequenceLayoutManager.finishPage(AbstractPageSequenceLayoutManager.java:312)
at org.apache.fop.layoutmgr.PageSequenceLayoutManager.finishPage(PageSequenceLayoutManager.java:167)
at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:109)
at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:238)
at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:120)
at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:349)
at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:177)
at net.sf.saxon.event.ContentHandlerProxy.endElement(ContentHandlerProxy.java:391)
at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:174)
at net.sf.saxon.event.NamespaceReducer.endElement(NamespaceReducer.java:213)
at net.sf.saxon.event.ComplexContentOutputter.endElement(ComplexContentOutputter.java:417)
at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:301)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:409)
at net.sf.saxon.instruct.Instruction.process(Instruction.java:94)
at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343)
at net.sf.saxon.Controller.transformDocument(Controller.java:1736)
at net.sf.saxon.Controller.transform(Controller.java:1560)
at mypackage.v2.business.pdf.XMLtoPDF.convertXMLPDF(XMLtoPDF.java:103)
... 51 more
java.lang.ClassCastException: java.lang.NoSuchMethodError cannot be cast to java.lang.Exception
`
Please let me know what could be the problem.
As described in the documentation
Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.
Here's how this can happen. Imagine you built some code that used a library with a method called foo(). You compiled your project and then later decided to upgrade the library. You do this by overwriting the old jar file with the new one. You don't recompile your code.
But what you didn't know is the new library removed the foo() method. Now if you run your code, it will throw this exception because your compile code calls this method and it's no longer there.
In your specific case, this isn't necessarily your code with the problem. It could be that you have one library that uses another library and the problem is there (for example, Library X uses version 2 of Library Y, but you only have Library Y version 1 in your classpath). If this is happening, you need to make sure the libraries are using the version they expect.
For your specific problem, you need to find the version of the jar that has org.apache.xmlgraphics.java2d.GraphicContext in it and it needs to have a constructor that takes a... list of org/apache/xmlgraphics/java2d/GraphicContext... maybe. I forget what (L...;)V means.

Categories

Resources