CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2003
    Posts
    4

    URGENT help needed: Calling Java Swing Classes from an Applet or JSP.

    Hi,

    I have a couple of questions:

    I have a complete stand-along Java application with GUI (using Swing) which I want to be able to called remotely. So I was thinking about putting it in a browser using Applet or JSP. Basically I have this compiled class file called "MappingApplication.class" which holds the code for the application that I tried calling from an applet but I am getting java.lang.NoClassDefFoundError: MappingApplication error. I have list the detailed stack trace below. I am not sure what to do. Anybody has any ideas? I do have Java Plug-in installed & I also tried using the HTML Converter from Sun but it didnt help.

    If somehow I can get that GUI Application to get called from the browser and run inside the browser or stand-alone that would be great.


    Any help would be appreciated.

    Thanks,
    V. Patel.



    java.lang.NoClassDefFoundError: MappingApplication (wrong name: com/mapforce/MappingApplication)

    at java.lang.ClassLoader.defineClass0(Native Method)

    at java.lang.ClassLoader.defineClass(Unknown Source)

    at java.security.SecureClassLoader.defineClass(Unknown Source)

    at sun.applet.AppletClassLoader.findClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    at sun.applet.AppletClassLoader.loadClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    at sun.applet.AppletClassLoader.loadCode(Unknown Source)

    at sun.applet.AppletPanel.createApplet(Unknown Source)

    at sun.plugin.AppletViewer.createApplet(Unknown Source)

    at sun.applet.AppletPanel.runLoader(Unknown Source)

    at sun.applet.AppletPanel.run(Unknown Source)

    at java.lang.Thread.run(Unknown Source)

  2. #2
    Join Date
    Sep 2003
    Location
    Spokane, Wa
    Posts
    147

    Smile

    Need more info. Need to know the code for the html page. If you are using IE then you need to switch to “Show Friendly HTTP Error Messages”. It’s in Internet Options. Changing this in IE will give a more accurate message in which to debug. Need to know the applet’s file directory. Also, need the applet's code. This error could be because the browser's SecurityManager is blocking the call to load the classes.

  3. #3
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    If somehow I can get that GUI Application to get called from the browser and run inside the browser or stand-alone that would be great
    Splitting hairs It won't runinside the browser... Unless it's an Applet, it won't run on the page either. But you can call your class from an applet and open a Window or Frame (whatever your app currently uses), but the applet has to find your class. You would need to include the class/package in the classpath, or be in the same directory, etc...
    Last edited by Goodz13; October 14th, 2003 at 05:48 PM.

  4. #4
    Join Date
    Oct 2003
    Posts
    4
    Thanks to everyone who replied back. You valuble feedback was appreciated. I have fixed my initial problem but I have 2 other questions now so any help for this would be appreciated as well.

    1. I have this HTML (see below) that has Applet tag in it which calls a pre-compiled Java class. That HTML by itself works great if its ran on a machine that has JRE/JDK and Java Plug-in installed. I also want it to be able to run in on computers where there is no Java Plug-in/JRE/JDK so I used Sun's HTML Converter 1.3 to convert my HTML. But the HTML Converter gave me errors saying that its unable to convert the HTML file. So I searched on the net for an already converted file and tried to modify my HTML but that didnt work. Any ideas on what I need to do? What am I missing?

    NOTE: The existing HTML code (see below) works great if JRE/JDK/Java Plug-in are already installed on the machine in which case I dont care if its converted or not.

    Here is the HTML code:

    <html>
    <head>
    <title>Mapping Application</title>
    </head>
    <body>
    <APPLET codebase="classes" CODE="com.mapforce.MappingApplication.class" WIDTH="800" HEIGHT="600"></APPLET>
    </body>
    </html>


    2. This same applet when called opens up a Java Swing application outside of the browser. It has a button which (when clicked) will connect the Java Swing application to a MS Access database. Below is the code that will be executed whn the "Connect" button is clicked. When I run the application on its own from DOS command line or from JBuilder it works great and no errors. But when I popup this Java Swing application from an Applet, it launches fine but when I click on that "Connect" Button it gives me following error: ERROR: access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc). My guess is that the Applet does not have permission? How and where would I set it? The applet HTML itself is same as above.



    Here is the code that will be executed when the "Connect" button is clicked:
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    MappingMain1 MappingMain1Object = new MappingMain1();
    MappingMain1Object.registerTraceTarget(ttc);
    MappingMain1Object.run(java.sql.DriverManager.getConnection(
    "jdbcdbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=L:/VPatel/ClaimsDirectory/OfficeListing.mdb",
    "",""),"OfficeListing.xml");
    jTraceTextArea.append("Finished\n");
    } catch (Exception ex) {
    jTraceTextArea.append("ERROR: " + ex.getMessage());
    }


    Thanks and I'll appreciate all the help I can get.
    V. Patel.

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104
    erm.. you will have serious difficulty running a java application on a computer that doesnt have a JRE installed.. kinda like expecting MS Word to run on a computer that doesnt have windows installed

    and your second question is likely to do with the permissions assigned to the security manager for applets.. to get the permission, you normally have to request it from the user, or alter the security configuration on their machine (which requires access to the machine in person.. applets are fairly well constraiend)

  6. #6
    Join Date
    Sep 2003
    Location
    Spokane, Wa
    Posts
    147

    Unhappy

    I hate to be a stick in the mud, but right now, writing a Java Applet is a “Dead End Street”. Micro$oft is no longer under any obligations to writing another line of code for Java Virtual Machine. Right now only Micro$oft can write the JVM for Windows. Also, AOL is thinking about dropping Netscape. It really doesn’t look good for Java as a client side programming language. I suggest that you drop the applet and write JSP, Servlets and Enterprise Java Beans.

  7. #7
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104
    only microsoft can write the jvm for windows? i wasnt aware that they ever did...

  8. #8
    Join Date
    Oct 2003
    Posts
    4
    Thanks all of you guys for your input. I got what I wanted to do and its working great. Thank you so very much for your valuble time and input.

    I appreciate it all.


    V. Patel.

  9. #9
    Join Date
    Jun 2010
    Posts
    1

    Angry Re: URGENT help needed: Calling Java Swing Classes from an Applet or JSP.

    plzz can you tell me the solution.. am also geting the same problem... my problem is..
    i got executed my appletwith jdbcodbc in command prompt. but am not able to execute in broswer. its giving an exeception "Exception occured:java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)" plzz any body help me out.. its urgent...

  10. #10
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: URGENT help needed: Calling Java Swing Classes from an Applet or JSP.

    plzz can you tell me the solution
    I think it's unlikely vp98aa is going to answer your request for help, he/she only posted 4 times and that was 7 years ago and hasn't been seen on the forum since. Please don't resurrect old threads, start your own thread.

    Applets running in browsers have a very restrictive security policy. It looks like you have come up against this. You can supply a SecurityManager and/or policy file to relax the security policy for the area you need access to, but without more information on what you are doing it's hard to give definitive advice.

    You need to read up on applet security, I suggest you google "applet security" and read the many articles on fixing such problems.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured