Message Boards Message Boards

1
|
14350 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How do I fix this error when importing a custom Java class in J/Link?

Posted 10 years ago

Hi folks,

I just recently started experimenting with the Mathematica J/Link extension, and decided to try and utilize a small custom Java class within Mathematica. The class is simple and runs perfectly well within Eclipse, but when I tried to follow the instructions for importing a Java class with J/Link at http://reference.wolfram.com/language/JLink/tutorial/CallingJavaFromTheWolframLanguage.html, I found that I kept getting the error:

**"A Java exception occurred: "java.lang.UnsupportedClassVersionError: \ MyClass : Unsupported major.minor version 52.0"**

The above error was the result of the LoadJavaClass[] function. The simple code I had used up to this point was as follows:

Needs["JLink`"]
InstallJava[]
AddToClassPath["/My/Project/Class/Path/"]
LoadJavaClass["MyClass"]

With /My/Project/Class/Path/ as the directory path to the class and MyClass as the .class file itself, respectively.

I'm currently running java version "1.8.0_25", Mathematica 10.0.1.0, and Eclipse 4.4.1, if any of that makes a difference.

Thank you to anyone who has a few minutes to help explain to me what I'm doing wrong and hopefully how to go about doing it correctly.

-Wren

POSTED BY: Wren Rudolph
4 Replies

I found that you do not need to do the ReinstallJava[]:

This works and solves the problem:

Needs["JLink`"];

InstallJava[CommandLine -> "/usr/bin/java"];

AddToClassPath["/Users/xxxx/WhereverYouWantThis"];

POSTED BY: Neil Singer

Tks Jean! It solver my problem too. Very useful.

POSTED BY: Rodrigo Murta

Hi,

Nobody seems to have replied to your post after 5 months. Did you eventually find a solution or just gave up? I am encountering the same problem with code that used to run just fine with Mathematica 8 and JDK 7 about 1.5 year ago.

Thank you in advance for any help or pointers.

jyh.

POSTED BY: Jean-Yves Hervé

I know it's silly and bad form to reply to my own post, but minutes after hitting the "Publish" button I found out that all I had to do was to point JLink to the correct location of the java executable. So, with the current versions of JDK 8, this gives:

Needs["JLink`"]; InstallJava[]; ReinstallJava[CommandLine -> "/usr/bin/java"];

and then after that everything works fine for me.

POSTED BY: Jean-Yves Hervé
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract