S
saifnobel
Hi,
I recently installed the JMatlink library (to call Matlab from java)
on my computer. Everything works well as long as I use an application
with a main method. For example the following code works well:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
public class f
{
public static void main(String[] args)
{
JMatLink eng = new JMatLink();
eng.engOpen();
}
}
However, when I use the same code in an applet, things go haywire.
Following is my applet code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
public class tst extends Applet implements ActionListener
{
Button okButton;
public void init()
{
setLayout(new FlowLayout());
okButton = new Button("Action!");
add(okButton);
okButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == okButton)
{
System.out.println("Action");
JMatLink eng = new JMatLink();
eng.engOpen();
repaint();
}
}
}
It compiles well. But when I click on the Action button in the applet,
following are the errors the system throws:
C:\JMatLink>appletviewer dal.html
Action
Exception in thread "AWT-EventQueue-1"
java.security.AccessControlException: acc
ess denied (java.lang.RuntimePermission loadLibrary.JMatlink)
at
java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at
java.security.AccessController.checkPermission(AccessController.java:
546)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkLink(SecurityManager.java:
818)
at java.lang.Runtime.loadLibrary0(Runtime.java:817)
at java.lang.System.loadLibrary(System.java:1030)
at tst.actionPerformed(tst.java:25)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:
121)
C:\JMatLink>
I would appreciate if you could help.
Saif
---------
On Dec 2, 7:22 am, (e-mail address removed) wrote:
....
Applets that load natives need to be 'full-trust'. That means that
not
only does the applet have to be signed, but the user has to 'accept'
the signed code at the prompt.
BTW - if you want to provide a 'link to see the project' to other
people, you are probably better off looking to a JWS launch, than
applets.
This page has some JWS examples, including a combined
applet/application. <http://www.physci.org/jws/#jtest>
--
Andrew T.
PhiySci.org
-------
Thank you so much for your message Andrew. You are absolutely right
that my final aim is to be able to interact with the Matlab engine
remotely over the Internet.
The JWS idea was excellent. I was not aware that such a technology
existed where we could do away with Applets for web applications! I
researched a bit and then installed NetBeans 5.1.1 IDE. This has
capabilities of configuring an application to run with JWS.
I tried again with my earlier code but the problem remains the same.
The following simple swing code (which also calls the Matlab engine)
works well as long as I run it as an application:
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author Saif Ahmad
*/
public class Hello {
public static void main(String[] args) {
JFrame frame = new JFrame("HelloWorldSwing");
final JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
JMatLink eng = new JMatLink();
eng.engOpen();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
However, when I run the above with JWS, I get the following errors:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at Hello.main(Hello.java:23)
.... 9 more
Caused by: java.security.AccessControlException: access denied
(java.lang.RuntimePermission loadLibrary.JMatLink)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkLink(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at JMatLink.<clinit>(JMatLink.java:147)
.... 10 more
On the other hand, as soon as I comment out the lines:
//JMatLink eng = new JMatLink();
//eng.engOpen();
The swing application runs faultlessly with JWS! Any help would be
greatly appreciated.
Cheers,
Saif
------
The same (or very similar) security sandbox applies to JWS
projects. It is only 'plain old' applications that have no security
manager at all.
There is a lot more I could ask/suggest, but I won't do it ..here
on this group. If you want to pursue this matter, I suggest you
make a post to comp.lang.java.programmer, a group I regularly
read. The only way I notice posts here, is via. 'Google Alerts' -
which take some time to arrive.
--
Andrew T.
-----
Hi Andrew,
I am posting to this group in the hope that you would be able to guide
me to solve my problem.
Best wishes,
Saif
I recently installed the JMatlink library (to call Matlab from java)
on my computer. Everything works well as long as I use an application
with a main method. For example the following code works well:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
public class f
{
public static void main(String[] args)
{
JMatLink eng = new JMatLink();
eng.engOpen();
}
}
However, when I use the same code in an applet, things go haywire.
Following is my applet code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
public class tst extends Applet implements ActionListener
{
Button okButton;
public void init()
{
setLayout(new FlowLayout());
okButton = new Button("Action!");
add(okButton);
okButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == okButton)
{
System.out.println("Action");
JMatLink eng = new JMatLink();
eng.engOpen();
repaint();
}
}
}
It compiles well. But when I click on the Action button in the applet,
following are the errors the system throws:
C:\JMatLink>appletviewer dal.html
Action
Exception in thread "AWT-EventQueue-1"
java.security.AccessControlException: acc
ess denied (java.lang.RuntimePermission loadLibrary.JMatlink)
at
java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at
java.security.AccessController.checkPermission(AccessController.java:
546)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkLink(SecurityManager.java:
818)
at java.lang.Runtime.loadLibrary0(Runtime.java:817)
at java.lang.System.loadLibrary(System.java:1030)
at tst.actionPerformed(tst.java:25)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:
121)
C:\JMatLink>
I would appreciate if you could help.
Saif
---------
On Dec 2, 7:22 am, (e-mail address removed) wrote:
....
I recently installed the JMatlink library (to call Matlab from java)
on my computer. ....
However, when I use the same code in anapplet, things go haywire.
Following is myappletcode: ....
C:\JMatLink>appletviewer dal.html
Action
Exception in thread "AWT-EventQueue-1"
java.security.AccessControlException: acc
ess denied (java.lang.RuntimePermission loadLibrary.JMatlink)
Applets that load natives need to be 'full-trust'. That means that
not
only does the applet have to be signed, but the user has to 'accept'
the signed code at the prompt.
BTW - if you want to provide a 'link to see the project' to other
people, you are probably better off looking to a JWS launch, than
applets.
This page has some JWS examples, including a combined
applet/application. <http://www.physci.org/jws/#jtest>
--
Andrew T.
PhiySci.org
-------
Thank you so much for your message Andrew. You are absolutely right
that my final aim is to be able to interact with the Matlab engine
remotely over the Internet.
The JWS idea was excellent. I was not aware that such a technology
existed where we could do away with Applets for web applications! I
researched a bit and then installed NetBeans 5.1.1 IDE. This has
capabilities of configuring an application to run with JWS.
I tried again with my earlier code but the problem remains the same.
The following simple swing code (which also calls the Matlab engine)
works well as long as I run it as an application:
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author Saif Ahmad
*/
public class Hello {
public static void main(String[] args) {
JFrame frame = new JFrame("HelloWorldSwing");
final JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
JMatLink eng = new JMatLink();
eng.engOpen();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
However, when I run the above with JWS, I get the following errors:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at Hello.main(Hello.java:23)
.... 9 more
Caused by: java.security.AccessControlException: access denied
(java.lang.RuntimePermission loadLibrary.JMatLink)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkLink(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at JMatLink.<clinit>(JMatLink.java:147)
.... 10 more
On the other hand, as soon as I comment out the lines:
//JMatLink eng = new JMatLink();
//eng.engOpen();
The swing application runs faultlessly with JWS! Any help would be
greatly appreciated.
Cheers,
Saif
------
The same (or very similar) security sandbox applies to JWS
projects. It is only 'plain old' applications that have no security
manager at all.
There is a lot more I could ask/suggest, but I won't do it ..here
on this group. If you want to pursue this matter, I suggest you
make a post to comp.lang.java.programmer, a group I regularly
read. The only way I notice posts here, is via. 'Google Alerts' -
which take some time to arrive.
--
Andrew T.
-----
Hi Andrew,
I am posting to this group in the hope that you would be able to guide
me to solve my problem.
Best wishes,
Saif