ruby class to java class using jruby - java

i found the following ruby app in git:
https://github.com/chrislo/sourceclassifier
and it is exactly what i need for the final part of my school project.
It would be great if i could use it in a my java project.
i used jRuby and managed to compile the class i need ( sourceclassifier.rb ) to a Java .class file, and added it to the build path of my eclipse app.
how can i now use it inside my app?
using sourceclassifier s = new sourceclassifier() throws me the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: sourceclassifier/lib/sourceclassifier
at StackOverFlowReader.main(StackOverFlowReader.java:208)
Caused by: java.lang.ClassNotFoundException: sourceclassifier.lib.sourceclassifier
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`
and help will be appreciated,
Boris.

Related

Adding Jar Plugins Dynamically, but issuing NoClassDefFoundError

I am recently making a PluginClassLoader to load java plugins to my programs dynamically. So that the plugins can interacts with my program.
However, things won't go nicely though. So I looked up with bukkit's implementation of loading plugins. [Bukkit's source code] I followed with it, Java still throws me a NoClassDefFoundError.
Here's my implementation:
All the plugins that to be added are extended to com.mob41.sakura.plugin.Plugin. This abstract class contains onCallPlugin(), onEndPlugin(), etc. functions for the main program to interact to them. [Abstract class source code]
All the plugins will be placed in a /plugins folder on the working directory (System.getProperty("user.dir") + "\\plugins"). My program will find the folder (/plugins) on the working directory. If it doesn't exist, it creates a new folder. If exists, it will find all the jar files. And create a PluginClassLoader [Source Code] to add the plugins.
I expected the plugins will be added to the my program and the classloader will create their instances. Through this testing code:
public static void main(String[] args) {
System.out.println("Loading...");
try {
PluginManager.getPluginManager().loadAllPlugins();
} catch (Exception e){
e.printStackTrace();
return;
}
System.out.println("Loaded.");
JSONObject json = new JSONObject();
json.put("ext", false);
System.out.println((JSONObject) PluginManager.getPluginManager().runPluginLifeCycle("Sakura-Plugin-HKOWeather", json));
}
If the plugin invalid/causes error when loading it, this exception will be thrown.
I don't know why my program cannot find the plugin that extended itself...
com.mob41.sakura.plugin.exception.InvalidPluginException: java.lang.NoClassDefFoundError: com/mob41/sakura/plugin/Plugin
at com.mob41.sakura.plugin.PluginManager.loadPlugin(PluginManager.java:180)
at com.mob41.sakura.plugin.PluginManager.loadAllPlugins(PluginManager.java:145)
at com.mob41.sakura.Main.main(Main.java:12)
Caused by: java.lang.NoClassDefFoundError: com/mob41/sakura/plugin/Plugin
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.mob41.sakura.plugin.PluginClassLoader.<init>(PluginClassLoader.java:25)
at com.mob41.sakura.plugin.PluginManager.loadPlugin(PluginManager.java:176)
... 2 more
Caused by: java.lang.ClassNotFoundException: com.mob41.sakura.plugin.Plugin
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
Through hours of debugging, I finally found the answer.
I was specifying a wrong ClassLoader to my implementation of PluginClassLoader.

Eclipse Run jar file in cmd where class descrition is in different junit class

I have created a Junit class which runs individually. Now for creating a jar file a i have created a different java class in same package. And in that class i have mentioned junit class name as JUnitCore.runClasses(IMageCredit.class);
Manifest file is ok.
when i am running jar file using cmd it is showing following error
Exception in thread "main" java.lang.NoClassDefFoundError: rahul/IMageCredit
at rahul.TestRunner.main(TestRunner.java:11)
Caused by: java.lang.ClassNotFoundException: rahul.IMageCredit
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

Java programs cannot run after downloading opencsv

I downloaded the opencsv (from http://sourceforge.net/projects/javacsv/files/latest/download) and since then I have been getting this error with all my Java programs
java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main"
How can I fix this? I realized I didn't need the opencsv anyway...how can I remove it so that my programs can compile and run as usual? I'm using Eclipse Version: 1.4.2.20120213-0813
You can remove a plugin by going to Help->About (or Eclipse->About on a Mac), choosing installations details, selecting the plugin you wish to remove, and choosing 'Uninstall'.

LibreOffice SDK bootstrap

I got the standard jar files + juh-2.4.1.jar and ridl-3.2.1.jar (got errors on import) as referenced libraries in my project. When i get an example piece of code from http://api.libreoffice.org/examples/DevelopersGuide/examples.html#FirstSteps i always land on this error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/star/comp/loader/JavaLoader
at com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(Bootstrap.java:118)
at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:241)
at TextDocuments.getRemoteServiceManager(TextDocuments.java:410)
at TextDocuments.storePrintExample(TextDocuments.java:378)
at TextDocuments.runDemo(TextDocuments.java:152)
at TextDocuments.main(TextDocuments.java:142)
Caused by: java.lang.ClassNotFoundException: com.sun.star.comp.loader.JavaLoader
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)
... 6 more
Always a NoClassDefFoundError on bootstrap.. Searching for this but can't find much.. Anybody has an idea how to fix this?
In my LibreOffice installation the missing class is located in the file jurt.jar

NoClassDefFoundError: scala/ScalaObject in mixed Scala/Java project

Background: I am a C# developer, but my next project needs to be on the JVM. I have researched Scala and I think that it lets me to what I can in C# (Lambdas, inferred types, functional-style, etc). I would classify myself as a very novice Java developer... especially when it comes to using the IDE's, etc.
I have a Scala project that seems to work...
I made a Java project and referenced the Scala project
The editor seems to know about the classes in the Scala project (typeahead, etc)
When I try to run the Java project, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(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)
at learning_scala.java.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
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)
Clearly something has gone awry in the Java/Scala compilation, but I have no idea how to resolve it (my lack of Java experience being the primary culprit here)
I'm using Eclipse w/ the official Scala plugin... all of which are up to date as of 2-3 days ago.
Thanks
You need to add the scala-library.jar library to your classpath. You can do that a few different ways but the simplest is to copy the file into your project (drag and drop it into your eclipse package explorer). Next, right click on the file and select add to build path. That adds the scala jar to your classpath. That should fix the problem.

Categories