Trouble with javaaddpath for a jar, it seems to load fine, but Matlab can't find classes inside...

7 views (last 30 days)
So, I'm trying to add a WorldWind map to my matlab application, WorldWind is open source and written in java. I'm trying to implement this example in Matlab to start off
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import javax.swing.*;
/**
* This example demonstrates the simplest possible way to create a WorldWind application.
*
* @version $Id: SimplestPossibleExample.java 1171 2013-02-11 21:45:02Z dcollins $
*/
public class SimplestPossibleExample extends JFrame
{
public SimplestPossibleExample()
{
WorldWindowGLCanvas wwd = new WorldWindowGLCanvas();
wwd.setPreferredSize(new java.awt.Dimension(1000, 800));
this.getContentPane().add(wwd, java.awt.BorderLayout.CENTER);
wwd.setModel(new BasicModel());
}
public static void main(String[] args)
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
JFrame frame = new SimplestPossibleExample();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
}
To do this in eclipse the only thing I had to do was add worldwind.jar to my javaclasspath. So, to do this in matlab I'm trying to do this
function Plot_World_Wind()
javaaddpath('C:\Users\Nellingson\Documents\Programs\worldwind-v2.1.0\worldwind.jar')
import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import javax.swing.*
h = figure;So
jf = get(h, 'JavaFrame');
jf = jf.fHG2Client.getWindow;
wwd = gov.nasa.worldwind.awt.WorldWindowGLCanvas();
wwd.setPreferredSize(java.awt.Dimension(1000, 800));
jf.getContentPane().add(wwd, java.awt.BorderLayout.CENTER);
wwd.setModel(BasicModel());
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
end
But when import gets callled, the classes inside worldwindwind.jar do not get found....
Error: File: Plot_World_Wind.m Line: 4 Column: 12
Arguments to IMPORT must either end with ".*" or else specify a fully qualified class name: "gov.nasa.worldwind.awt.WorldWindowGLCanvas" fails this
test.
I double chaecked to see that they are acutally inside that jar file. Then ran javap to ensure that the jar file was not compiled with a version of java that is too new.
javap -classpath worldwind.jar -verbose gov.nasa.worldwind.awt.WorldWindowGLCanvas | findstr major
major version: 52
Which I believe is the same version matlab 2018a uses. Im completely new to calling java from matlab. I have only used it by following examples pretty closely. Here I'm guessing there is something very obvious that I'm missing. After loading worldwind.jar I checked my known classes like this...
[~,knownjavaclasses,~] = cellfun(@fileparts,[javaclasspath('-dynamic'); javaclasspath('-static')],'uniformoutput',false)
ant the ones I'm looking for arn't there. Any ideas of what to try?
  2 Comments
Nathan Ellingson
Nathan Ellingson on 16 Nov 2018
So I noticed that I can acually load the other classes from worldwindow.jar, just not gov.nasa.worldwind.awt.WorldWindowGLCanvas... and one more gov.nasa.worldwind.awt.WorldWindowGLJPanel, which I assume is for the same reason.
Julien
Julien on 25 Nov 2020
Hello Nathan,
Quite an old post but I am experiencing exactly the same problem with MATLAB realeases newer than R2014b. I managed to make it working on older realeases (at least R2012b). Have you found a solution to this problem ?
I think this could be due to a conflict of gluegen-rt.jar and jogl-all.jar libraries which are now embedded with MATLAB (in matlabroot/java/jarext) since R2014b. Moreover these gluegen-rt.jar and jogl-all.jar libraries on which depend worldwind java project require native libraires (ressources actually) gluegen-rt-natives-linux-amd64.jar and jogl-all-natives-linux-amd64.jar (in linux).
Thanks in advance for your help!

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!