Source code:
package com.web;
import com.web.Operation;
import java.applet.*;
import java.awt.Graphics;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.io.*;
public class AppletExample extends Applet {
public void init() {
try {
getAppletContext().showDocument(new URL("file:///C:/Users/Victor/Desktop/test.txt"), "_blank");
}
catch (MalformedURLException ex) {
System.out.println(ex.getMessage());
}
}
public void paint( Graphics g ) {
Operation op = new Operation();
op.response();
g.drawString("Go File", 0,100);
}
}
When I run the Applet using the Appletviewer application the next error comes on screen:
C:\Users\Victor\Desktop\project2\src>appletviewer display.html
Warning: Can't read AppletViewer properties file: C:\Users\Victor\.hotjava\prope
rties Using defaults.
java.security.AccessControlException: access denied ("java.io.FilePermission" "C
:\Users\Victor\Desktop\test.txt" "write")
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:366)
at java.security.AccessController.checkPermission(AccessController.java:
555)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkWrite(SecurityManager.java:979)
at java.io.FileOutputStream.<init>(FileOutputStream.java:203)
at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
at java.io.FileWriter.<init>(FileWriter.java:63)
at com.web.Operation.response(Operation.java:15)
at com.web.AppletExample.paint(AppletExample.java:25)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264)
at sun.awt.RepaintArea.paint(RepaintArea.java:240)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:347)
at java.awt.Component.dispatchEventImpl(Component.java:4936)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:117)
This is what the class Operation does:
package com.web;
import com.web.AutomatedTelnetClient;
import java.util.*;
import java.io.*;
public class Operation {
public Operation() {
}
public void response() {
try {
BufferedWriter out = new BufferedWriter(new FileWriter("C://Users/Victor/Desktop/test.txt"));
AutomatedTelnetClient telnetClient = new AutomatedTelnetClient();
telnetClient.connect();
StringBuffer text = telnetClient.sendCommand("display gps");
telnetClient.disconnect();
out.write(text.toString());
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
It seems to be a permission problem to write in the file from the applet, isn't it? How can I solve it?
Since it is a file system of the client you are trying to write to. You need to create a jar with the class files and have to sign it as a trusted application. Follow this post on how to sign, then you that jar to load the applet.
Related
My friends and I have minecraft server and we want to add JavaMail plugin with Maven , We added 2 jar files:
Mail.jar
Activation.jar
With this code:
package com.parlagames;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class App {
public void AppVoid(String host, String port,final String userName,final String password, String[] toAddress, String subject, String message) {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port",port);
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
});
try {
Message SendMessage = new MimeMessage(session);
SendMessage.setFrom(new InternetAddress(userName));
for(int i=0;i<toAddress.length;i++) {
SendMessage.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(toAddress[i]));
SendMessage.setSubject(subject);
SendMessage.setContent(message, "text/html; charset=utf-8");
Transport.send(SendMessage);
}
System.out.println("Sent");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
When we start the plugin in his server it shows an error that it doesn't identify the class
java.lang.NoClassDefFoundError: com/parlagames/App
at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_161]
at java.lang.ClassLoader.defineClass(Unknown Source) ~[?:1.8.0_161]
at java.security.SecureClassLoader.defineClass(Unknown Source) ~[?:1.8.0_161]
at java.net.URLClassLoader.defineClass(Unknown Source) ~[?:1.8.0_161]
at java.net.URLClassLoader.access$100(Unknown Source) ~[?:1.8.0_161]
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_161]
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_161]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_161]
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_161]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
Why does it happend? we need to have the maven by the way
It seems that you need to add this line of code to the plugin:
public void onEnable()
and this code
public void onDisable()
It also seems that you don't have a main class. A main class is declared at plugin.yml. Try finding the part that says "main:" and change it to the class that has the "onEnable()" and "onDisable()". Also add extends JavaPlugin as someone said before
Is App the main class of your plugin ? If so, it you need to make it extend the JavaPlugin class like this :
public class MyPlugin extends JavaPlugin {
public void onEnable() {
}
public void onDisable() {
}
}
If you have trouble understanding of the bukkit/spigot API, I would suggest to start learning from the docs (here is a reference guide for the basics).
I have written a code which will play music when a link on a webpage is found.
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javafx.application.*;
// * #author Archit
public abstract class WebCrawl extends Application{
public static void main(String[] args) throws IOException {
Application.launch(args);
int a=0;
try {
Document doc = Jsoup.connect("https://in.bookmyshow.com/ranchi").get();
org.jsoup.select.Elements links = doc.select("a");
for (Element e: links) {
if ((e.attr("abs:href").equals("https://in.bookmyshow.com/ranchi/movies/fan/ET00025074"))) {
try {
File f = new File("/Users/Archit/Documents/Music/campbell.wav");
Media hit = new Media(f.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
} catch(Exception ex) {
System.out.println("Exception");
}
}
}
}
The error I am getting is this:
Exception in Application constructor java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class webcrawl.WebCrawl
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application webcrawl.WebCrawl
A window seems to open when I run the application but is automatically closed and this error appears.
I would really appreciate the help. Thank you.
You are starting an application from the WebCrawl class using Application.launch(String[]), so launch tries to create a WebCrawl instance, which it can't, since WebCrawl is abstract.
BTW: Placing code after the Application.launch call won't work, since after Application.launch is finished, the JavaFX platform will already have exited.
You can read about the application lifecycle in the Life-cycle section of the Application javadoc.
You need to call the code form the start method or later.
You can find a tutorial for a simple JavaFX application here: https://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm
I am currently stuck with the following prob. The JAR & Pi4J Lib gets executed on a RasPi B+. I've been searching the web for hours without a result. Curiously looking forward to your reponses and support ;-)
Stacktrace:
Exception in thread "main" java.lang.RuntimeException: Unable to open GPIO direction interface for pin [1]: No such file or directory
at com.pi4j.wiringpi.GpioUtil.export(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.export(RaspiGpioProvider.java:108)
at com.pi4j.io.gpio.impl.GpioPinImpl.export(GpioPinImpl.java:158)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionPin(GpioControllerImpl.java:517)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:669)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:681)
at com.test.RemoteImpl.fahreVorwaerts(RemoteImpl.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:178)
at sun.rmi.transport.Transport$1.run(Transport.java:175)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.fahreVorwaerts(Unknown Source)
at com.client.RMIClient.main(RMIClient.java:19)
package com.test;
The Code:
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import com.interf.test.TestRemote;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPin;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinDirection;
import com.pi4j.io.gpio.PinMode;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.trigger.GpioCallbackTrigger;
import com.pi4j.io.gpio.trigger.GpioPulseStateTrigger;
import com.pi4j.io.gpio.trigger.GpioSetStateTrigger;
import com.pi4j.io.gpio.trigger.GpioSyncStateTrigger;
import com.pi4j.io.gpio.event.GpioPinListener;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
import com.pi4j.io.gpio.event.PinEventType;
public class RemoteImpl extends UnicastRemoteObject implements TestRemote {
protected RemoteImpl() throws RemoteException {
super();
}
private static final long serialVersionUID = 1L;
#Override
public boolean isloginvalid(String username) throws RemoteException {
if (username.equals("test")) {
return true;
}
return false;
}
#Override
public void fahreVorwaerts(int dauer) throws RemoteException {
System.out.println("----- EXTCMD: VORWAERTS FAHREN "+"("+ dauer +"ms)" + "-----");
// GPIO CODE SECTION BEGINS
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput pin_gpio01 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.LOW);
pin_gpio01.pulse(dauer, true);
System.out.println("----- INFO: VORWAERTS FAHREN ENDE -----");
}
}
Life could have been so much easier if I'd just had a look on the GPIO numbering. There is no GPIO01!
Anyway, now it works by choosing an existing GPIO. Cheers :-)
Raspberry pi 3 B GPIO
pi4j; GPIO Input Error? "Unable to open GPIO edge interface for pin ??: No such file or directory"
-Solution-
Coding; gpio.setShutdownOptions(true) instead of myButton.setShutdownoptions(true) or gpio.shutdown()
Compile; Next, use the following command to compile this example program:
$ javac -classpath .:classes:/opt/pi4j/lib/'*' -d . ListenGpioExample.java
Execute the following command will run this example program:
$ sudo java -classpath .:classes:/opt/pi4j/lib/'*' ListenGpioExample
Run with sudo command
sudo java -jar yourjarname.jar
I'm trying to serialize a third-party class (which is not serializable) and I'm using xstream to do so.
At first I tried to build some class to see if it goes well and everything worked fine, But when I tried to convert the third-party instance to xml it thorws exceptions.
the code:
import java.util.List;
import java.util.Set;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import vohmm.application.SimpleTagger3;
public class Tagger{
public static void main(String[] args) {
try {
SimpleTagger3 tagger = new SimpleTagger3(args[0]);
XStream xStream = new XStream(new DomDriver());
String tagger_xml = xStream.toXML(tagger);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}
the exceptions:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sleepycat/je/DatabaseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
at java.lang.Class.getDeclaredMethod(Class.java:2002)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:164)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:148)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.supportsReadObject(SerializationMethodInvoker.java:105)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter.isSerializable(SerializableConverter.java:107)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter.canConvert(SerializableConverter.java:103)
at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:56)
at com.thoughtworks.xstream.XStream$1.lookupConverterForType(XStream.java:498)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:48)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1022)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1011)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:984)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:971)
at NewDemo.main(NewDemo.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.ClassNotFoundException: com.sleepycat.je.DatabaseException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 56 more
Is there a resone why xstream won't work with SimpleTagger3? Is there any other way to export java object?
Your classloader failed to load a class named 'com.sleepycat.je.DatabaseException'.
Make sure that this class is available. Try Class.forName("com.sleepycat.je.DatabaseException") to test if the class is available.
If not add it to your classpath or load it with a ClassLoader.
This applet worked fine until yesterday and now it is giving me some exception. Here is the stacktrace:
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getenv.localappdata")
Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
at java.security.AccessController.checkPermission(AccessController.java:560)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at sun.applet.AppletSecurity.checkAccess(AppletSecurity.java:252)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315)
at java.lang.Thread.init(Thread.java:376)
at java.lang.Thread.<init>(Thread.java:485)
at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.<init>(BasicDirectoryModel.java:222)
at javax.swing.plaf.basic.BasicDirectoryModel.validateFileCache(BasicDirectoryModel.java:140)
at javax.swing.plaf.basic.BasicDirectoryModel.propertyChange(BasicDirectoryModel.java:69)
at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
at java.awt.Component.firePropertyChange(Component.java:8382)
at javax.swing.JFileChooser.setCurrentDirectory(JFileChooser.java:581)
at javax.swing.JFileChooser.<init>(JFileChooser.java:344)
at javax.swing.JFileChooser.<init>(JFileChooser.java:296)
at gui1.jButton1ActionPerformed(gui1.java:148)
at gui1.access$000(gui1.java:21)
at gui1$1.actionPerformed(gui1.java:62)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
BUILD SUCCESSFUL (total time: 34 seconds)
I also created a policy file and put it in user.home directory with the name .java.policy
grant {
permission java.io.FilePermission "<<ALL FILES>>", "write";
permission java.lang.RuntimePermission "getenv.<environment variable name>";
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "delete";
};
Here is the applet code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import java.io.File;
import java.io.IOException;
/*
<applet code="mainapplet.java" width=500 height=500>
</applet>
*/
/**
*
* #author sabertooth
*/
public class mainapplet extends JApplet {
/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
private String localappfolder;
private String topath;
public void init() {
// TODO start asynchronous download of heavy resources
try{
localappfolder=System.getenv("localappdata");
topath=localappfolder+"\\ossoc\\";
new File(topath).mkdir();
}
catch(Exception e)
{
System.out.println(e);
}
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
public void destroy(){
}
// TODO overwrite start(), stop() and destroy() methods
private void createGUI(){
gui1 gui1=new gui1();
gui1.setOpaque(true);
setContentPane(gui1);
}
private static void deleteDir(File dir)
throws IOException
{
if (!dir.isDirectory()) {
throw new IOException("Not a directory " + dir);
}
dir.delete();
}
}
Please sign the Applet jar and use it in your code. Policy files are not the ideal solution to solve access problems.