3
$\begingroup$

I have a Java project compiled into a jar file with a class called HttpClientSSO.

The commandline

java -cp bota.jar org.nilostep.bota.HttpClientSSO

executes the class successfully.

I want to run the class from a Mathematica Notebook. I did the following:

Needs["JLink`"]
ReinstallJava[];
LoadJavaClass["java.lang.System"];
java`lang`System`getProperty["java.version"]
DIR = "D:\\Dropbox\\DATA\\MyJavaProjects\\bota\\out\\artifacts\\bota_jar\\bota.jar";
AddToClassPath[DIR];
frm = JavaNew["java.awt.Frame"]
conn = JavaNew["org.nilostep.bota.HttpClientSSO"]

Execution returns:

1.7.0_13

JavaObject[java.awt.Frame]

$Failed

In the Mathematica message frame I get the following error:

Java failed to load class org.nilostep.bota.HttpClientSSO. >>

I have also tried:

 ReinstallJava[ClassPath -> "D:\\Dropbox\\DATA\\MyJavaProjects\\bota\\out\\artifacts\\bota_jar\\bota.jar"]
 LoadJavaClass["org.nilostep.bota.HttpClientSSO"];
 conn = JavaNew["org.nilostep.bota.HttpClientSSO"]

but also with the result $Failed

How do I fix this?

$\endgroup$

1 Answer 1

3
$\begingroup$

The problem was the following, the custom .jar was created with Java 8, Mma 10.3 comes with Java 7, the real error was a version issue.

Needs["JLink`"]
DIR = "D:\\Dropbox\\DATA\\MyJavaProjects\\bota\\out\\artifacts\\bota_jar\\bota.jar";
ReinstallJava[CommandLine -> "C:\\Progra~1\\Java\\jdk1.8.0_45\\jre\\bin\\java", ClassPath -> DIR];
LoadJavaClass["java.lang.System"];
java`lang`System`getProperty["java.version"]
frm = JavaNew["java.awt.Frame"]
(*AddToClassPath[DIR];*)
conn = JavaNew["org.nilostep.bota.HttpClientSSO"]

worked as expected.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.