I wrote a signed applet which can receive file and write it to local machine file directory. I work on windows 7 with NetBeans. In the Appletviewer all runs correctly. But when I run the applet in context with my webpages in a web browser, the applet can create a file in a local directory, but I can’t use the copyFile() method from apache common.io. I can write into the file created using bufferedWriter(), but not using fileWriter. I need to transcode the file from .wav to .mp3 using the Encoder from the Java library, but it does not work in the browser. (I tried users home folder and other folders, but the result is the same.)
Here is the code of my attempt to implement file copying. No exception is thrown, but the file is not copied either.
try {
FileUtils.copyFile(source, target);
} catch(IOException e){
jLabel4.setText("Error: " + e.getMessage());
}
i can catch exceptions so here is text from my Java console when i push the button which should do copy :
try { FileUtils.copyFile(fl1, fl2); } catch (IOException ex) { ex.printStackTrace(); jLabel4.setText("Error: " + ex.getMessage()); }
here is my java console text:
basic: Told clients applet is started
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Connecting http://localhost:8084/ with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/, version: null]
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/org/apache/commons/io/FileUtils.class, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/org/apache/commons/io/FileUtils.class with proxy=DIRECT
Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
at SoundApplet.SoundApplet.jButton2ActionPerformed(SoundApplet.java:480)
at SoundApplet.SoundApplet.access$800(SoundApplet.java:42)
at SoundApplet.SoundApplet$11.actionPerformed(SoundApplet.java:304)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 38 more
it seems that is something bad with imported libraries. i added jars via right click on librariesfolder and add jar. I atach a image of my projects folder, may it help you understand my problem but it can be aloowed me it because i have already lower count of comments then 10 .
PROBLEM SOLVED!!
I have a little tutorial for people which will be so hopeless like me
in properties/packing options of your webproject add your applet project. it cause that .jar file from your applet will be compiled and copied into your build/web folder of you webroject automaticly when you run webproject.
if you want to use external libs for your APplet you must add their .jars into build/web folder of you webroject. Now, when you click run Webproject your applet is automaticly compiled into build/web folder of you webroject where are your external libs .jars too. (here be aware with Clean your project because it cause that your whole build folder is deleted and is builded again but Without your external libs .jars !! when it occurs you must copy .jars here again)
Now you must tell in html page what it neccesary do for load applet so you use this tag
<
applet codebase="http://localhost:8084/<nameOfyourWebProject>" code="<package>.<appletFileName>" archive="Applet.jar, <EXternalLibName1>.jar, <EXternalLibName2>.jar... " width="500" height="500"></applet>codebase is usualy your build/web folder (here is index.html too), so you say by this that Java will search jars from here. Code is path to your starting applet class. Archive tells which jars will be loaded so you need load jar of your applet and external libs jars too. You can specify how many jars you want… Thats all, now you can run your Web project and enjoy your loaded applet with external libs jars. BUT if you wanted to do something what unsigned applet cant(what applet can and cant) you must sign your applet.jar(that is possible via project properties) and you must sign all used jars for your applet(that is for testing posible via keytool and jarsign utulity distributed with java)
I spent a lot of time to get to know this informations and succesfuly run my project so i hope to this little tutorial help you stop waste time 🙂