Two Laptop Bag*
The moose likes Applets and the fly likes new to applet deployment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "new to applet deployment" Watch "new to applet deployment" New topic
Author

new to applet deployment

Patrick Martz
Greenhorn

Joined: Dec 12, 2009
Posts: 18
Hello all,
I'm somewhat new to applets and web serving in general. I have wrote some code for a JApplet form that is working great. I've used JavaLibrary, WebApplication, and normal java projects to start my development. with all the new glassfish server technology coming out from SUN i am getting lost in all of the different deployment options. At this point i want to take my basic NewJApplet.java src code and build the necessary .jar or .war file i may need to serve a web page applet, either through html or php or jsp or servlets. I also just purchased the Head First Servlets and JSP book written by the original creator of this web site. I get the feeling i don't need this book because of all the new technologies. If someone could lead me in the proper direction. I have jre 6, apache tomcat, WAMP, JEE 5 SDK , and these cover most if not all my servers on this machine. My applet needs to show a GUI to the user through java code and already has a JDBC with a mysql bin connector .jar file helping out, the user enters in information and updates the database with the new record and has accesss to all records at the same time and can ultimately print stuff out. I seem to have most of my troubles relating to web development because inside of the IDE's (netbeans / eclipse) the applet viewer runs my applet fine and it works with the DB but any attempt to use JNLP or HTML with applet tags just seems to be going nowhere.

thanks,
Patrick
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
Welcome to JavaRanch.

I'd guess the problems arise because the class files are not in the place where they need to be. In particular, they can't be inside fo WEB-INF, but instead they need to be in a publicly accessible directory. You may wish to read up on the details of applet deployment: http://faq.javaranch.com/java/AppletsFaq#tag


Ping & DNS - my free Android networking tools app
Patrick Martz
Greenhorn

Joined: Dec 12, 2009
Posts: 18
You want me to use a Web Application then inside of Netbeans or something, compile to get my class file. Make my html page with the proper tags and make sure the class file is not inside the WEB-INF folder but close to the .html file directory.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
You want me to use a Web Application

No. If this is just an applet with no server-side action happening, then there's no point of making it a web app. But you were talking of war files, JSPs, servlets and such, so I figured this was a Java web app.
Patrick Martz
Greenhorn

Joined: Dec 12, 2009
Posts: 18
i ran a few different configurations recommended by sun's tutorials for applets, and the closest one to actually opening the program seemed to be an HTML and JNLP file. i'll report the errors and file code and any directory structure, because i'm horrible at pointing in all these files. more to come...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
Um ... applets don't use JNLP files - JavaWebStart applications do. I recommend to use the time-honored <applet> tag; in my experience that works best these days.
Patrick Martz
Greenhorn

Joined: Dec 12, 2009
Posts: 18
ok, i got the applet tags to work with a second applet im working on. It has no mysql jdbc database connections. My other applet which uses the jdbc mysql connector jar and accesses a host on our intranet server will not make the connection without getting access denied errors and socket permission problems. I am working through the sun tutorials and learning pages to learn about policies and anything else i need to get it to display. Jar signing seems very involved and i hope that isn't required. but policy edits and other corrections seem to be making some differences, but im not entirely sure yet. I can send the errors when i get back to it tomorrow. thanks Ulf Dittmer
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
Yes, applets can't access network hosts other than the one they're served from without either being signed, or the local security policy altered. If other people besides you are supposed to use the applet then I'd advise to go with signing; altering policy files isn't something that most people would know how to do.

Some more info about the process is at HowCanAnAppletReadFilesOnTheLocalFileSystem.
Patrick Martz
Greenhorn

Joined: Dec 12, 2009
Posts: 18
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2214)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:781)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at appletrir.NewJApplet$STPanel.getConnection(NewJApplet.java:1823)
at appletrir.NewJApplet$STPanel.getVendors(NewJApplet.java:395)
at appletrir.NewJApplet$STPanel.<init>(NewJApplet.java:216)
at appletrir.NewJApplet.createAndShowGUI(NewJApplet.java:140)
at appletrir.NewJApplet.access$000(NewJApplet.java:38)
at appletrir.NewJApplet$1.run(NewJApplet.java:162)
at java.awt.event.InvocationEvent.dispatch(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.security.AccessControlException: access denied (java.net.SocketPermission alpha resolve)
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.checkConnect(Unknown Source)
at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:243)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2137)
... 25 more
java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at appletrir.NewJApplet.init(NewJApplet.java:155)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at appletrir.NewJApplet$STPanel.getVendors(NewJApplet.java:396)
at appletrir.NewJApplet$STPanel.<init>(NewJApplet.java:216)
at appletrir.NewJApplet.createAndShowGUI(NewJApplet.java:140)
at appletrir.NewJApplet.access$000(NewJApplet.java:38)
at appletrir.NewJApplet$1.run(NewJApplet.java:162)
at java.awt.event.InvocationEvent.dispatch(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)



this be the error of my ways. i edited my policy file as :
/* AUTOMATICALLY GENERATED ON Tue Dec 15 14:59:51 EST 2009*/
/* DO NOT EDIT */

grant {
permission java.security.AllPermission;
};

grant {
permission java.net.SocketPermission "alpha", "resolve";
permission java.net.SocketPermission "127.0.0.1:3306", "connect,resolve";
};


i also attempted to run it from the local server it is going to be hosted on and that made no difference and continued seeing errors.
i'll read up on signing for now, thanks again
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
What do you mean by "my policy file"? Where is it located? Are you sure that it is being used?
Patrick Martz
Greenhorn

Joined: Dec 12, 2009
Posts: 18
the applet.policy file in the projects root folder, it is auto made before i do any policy work. by default it had "grant {
permission java.security.AllPermission;
};
"

changing it to the link's specifications here under > Reading a Stack Trace > it didn't help, i still got the error in the above reply.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
Policy files aren't used simply by virtue of their existence - you either need to change the system policy file (which should be in JAVA_HOME/lib/security), or find a way to start the applet JVM so that some specific different policy file is used. The link you posted shows how to do that with appletviewer; I'm not sure if browsers can be instructed to use arbitrary additional JVM parameters for the applet JVM.
Patrick Martz
Greenhorn

Joined: Dec 12, 2009
Posts: 18
I got it to work today, had some slight print errors but looked good on all kinds of browsers. Changing the server's and client's different java policy files and security files remedied everything. the socket permissions were the main problem, and adding different codebases helps based on what all is being accessed.
I really appreciate all your help. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new to applet deployment