Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Java Applets (jar) in MFC resources application

Java Applets (jar) in MFC resources application

Scheduled Pinned Locked Moved C / C++ / MFC
questionjavascriptc++javacom
10 Posts 4 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Crercio O Silva
    wrote on last edited by
    #1

    Hi, I've been developing MFC (HTMLView) applications for quite sometime now. In order to reference the images and javascript .js file I used the res://app.exe/ protocol and it works just fine. In my last project I need to use a java applet library .jar but no matter what I try it doesn't work unless the java applet is in a webserver. I have used the following approaches: - codebase file://C:/dir/file.jar => failed - archive file://C:/dir/file.jar => failed - codebase res://app.exe/file.jar => failed - archive res://app.exe/file.jar => failed - codebase http://webserver/file.jar => success - archive http://webserver/file.jar => success The question is: How can I use a java applet in an MFC application without using a webserver? Thanks a lot for any lights on this. Crercio O. Silva / DBTools Development http://www.dbtools.com.br

    J A 2 Replies Last reply
    0
    • C Crercio O Silva

      Hi, I've been developing MFC (HTMLView) applications for quite sometime now. In order to reference the images and javascript .js file I used the res://app.exe/ protocol and it works just fine. In my last project I need to use a java applet library .jar but no matter what I try it doesn't work unless the java applet is in a webserver. I have used the following approaches: - codebase file://C:/dir/file.jar => failed - archive file://C:/dir/file.jar => failed - codebase res://app.exe/file.jar => failed - archive res://app.exe/file.jar => failed - codebase http://webserver/file.jar => success - archive http://webserver/file.jar => success The question is: How can I use a java applet in an MFC application without using a webserver? Thanks a lot for any lights on this. Crercio O. Silva / DBTools Development http://www.dbtools.com.br

      J Offline
      J Offline
      Johnny
      wrote on last edited by
      #2

      Not sure exactly what you are trying to do, but an applet must run within Java, whether thats from the command line or within an HTML page. Look at http://www.juicystudio.com/tutorial/html/object.asp for information on how to embed in HTML, and you will need to use the 'codebase' attribute to specify the jar file.

      C 1 Reply Last reply
      0
      • J Johnny

        Not sure exactly what you are trying to do, but an applet must run within Java, whether thats from the command line or within an HTML page. Look at http://www.juicystudio.com/tutorial/html/object.asp for information on how to embed in HTML, and you will need to use the 'codebase' attribute to specify the jar file.

        C Offline
        C Offline
        Crercio O Silva
        wrote on last edited by
        #3

        Hi, Thanks but I know how to embed the applet in my HTML page. As a matter of fact the problem only occurs when the applet is in the application resources like I can do with HTML pages, CSS files, GIF/JPG images, etc. Unfortunatelly it doesn't work with applets. Bellow you can see the part of the code I'm using to load the applet: The thing is, if I use this code in a page in my webserver it works correctly since the jar is in the same directory as the page is. But I do wnat to load this applet from the application resources or externally using the file:///C:/folder/ protocol. I have tested the file:/// protocol and it works if the HTML page is on disk but in my case the HTML page is in the resource. If it still not clear, please just let me know. Thanks again, Crercio O. Silva / DBTools Development http://www.dbtools.com.br

        S 1 Reply Last reply
        0
        • C Crercio O Silva

          Hi, Thanks but I know how to embed the applet in my HTML page. As a matter of fact the problem only occurs when the applet is in the application resources like I can do with HTML pages, CSS files, GIF/JPG images, etc. Unfortunatelly it doesn't work with applets. Bellow you can see the part of the code I'm using to load the applet: The thing is, if I use this code in a page in my webserver it works correctly since the jar is in the same directory as the page is. But I do wnat to load this applet from the application resources or externally using the file:///C:/folder/ protocol. I have tested the file:/// protocol and it works if the HTML page is on disk but in my case the HTML page is in the resource. If it still not clear, please just let me know. Thanks again, Crercio O. Silva / DBTools Development http://www.dbtools.com.br

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          I think there's a res: protocol for loading stuff from resources. Steve S

          C 1 Reply Last reply
          0
          • S Steve S

            I think there's a res: protocol for loading stuff from resources. Steve S

            C Offline
            C Offline
            Crercio O Silva
            wrote on last edited by
            #5

            I've already done that, and that's the problem it doesn't load the applet with the res:// protocol nor using the file:/// if the browser is embbeded in an MFC application. I could successfully write an html page to load in IE using both file:/// and http:// protocols but it comes to MFC application the only way to load the applet is using the http:// protocol, file:/// and res:// don't work. Any suggestions. Crercio O. Silva / DBTools Development http://www.dbtools.com.br

            S 1 Reply Last reply
            0
            • C Crercio O Silva

              I've already done that, and that's the problem it doesn't load the applet with the res:// protocol nor using the file:/// if the browser is embbeded in an MFC application. I could successfully write an html page to load in IE using both file:/// and http:// protocols but it comes to MFC application the only way to load the applet is using the http:// protocol, file:/// and res:// don't work. Any suggestions. Crercio O. Silva / DBTools Development http://www.dbtools.com.br

              S Offline
              S Offline
              Steve S
              wrote on last edited by
              #6

              Sorry, didn't read the root message. When you specify res://exe-name/resource, is the resource specified as HTML or JAR (or something else)..? At the back of my mind is that there was some kind of problem with this on Win9x at some point. Steve S

              C 1 Reply Last reply
              0
              • C Crercio O Silva

                Hi, I've been developing MFC (HTMLView) applications for quite sometime now. In order to reference the images and javascript .js file I used the res://app.exe/ protocol and it works just fine. In my last project I need to use a java applet library .jar but no matter what I try it doesn't work unless the java applet is in a webserver. I have used the following approaches: - codebase file://C:/dir/file.jar => failed - archive file://C:/dir/file.jar => failed - codebase res://app.exe/file.jar => failed - archive res://app.exe/file.jar => failed - codebase http://webserver/file.jar => success - archive http://webserver/file.jar => success The question is: How can I use a java applet in an MFC application without using a webserver? Thanks a lot for any lights on this. Crercio O. Silva / DBTools Development http://www.dbtools.com.br

                A Offline
                A Offline
                antlers
                wrote on last edited by
                #7

                Short answer is: Sorry, can't be done. When you start a Java applet, the browser passes the URL of the applet codebase to the Java Virtual Machine. The JVM is not going to understand a res: URL, and it is specifically prohibited from using a file: URL to load an applet because of all sorts of security problems. What you should be able to do is run the applet as a regular Java application, in which case the JVM is free to access the local disk to find the Jar file. Often applets will also have a "main" function that lets you run them as a regular application; if yours does not you will have to write another Java class with a "main" function that creates a frame and starts the applet within it. If your applet code needs tighter integration with your MFC app than running as a separate Java process will allow, you might have to look at the JNI (Java Native Interface), or whatever the equivalent is for Microsoft's brain-damaged JVM, to incorporate the Java runtime into your application.

                C 1 Reply Last reply
                0
                • S Steve S

                  Sorry, didn't read the root message. When you specify res://exe-name/resource, is the resource specified as HTML or JAR (or something else)..? At the back of my mind is that there was some kind of problem with this on Win9x at some point. Steve S

                  C Offline
                  C Offline
                  Crercio O Silva
                  wrote on last edited by
                  #8

                  Hi Steve, The jar file is specified as HTML, as it is the images and javascripts files. One funny thing is: I have just made a page in FrontPage using the file:/// protocol and the page works fine in the browser. If I use the same page in the application resources I got a Exception in the applet location in the page. Thanks Crercio O. Silva / DBTools Development http://www.dbtools.com.br

                  1 Reply Last reply
                  0
                  • A antlers

                    Short answer is: Sorry, can't be done. When you start a Java applet, the browser passes the URL of the applet codebase to the Java Virtual Machine. The JVM is not going to understand a res: URL, and it is specifically prohibited from using a file: URL to load an applet because of all sorts of security problems. What you should be able to do is run the applet as a regular Java application, in which case the JVM is free to access the local disk to find the Jar file. Often applets will also have a "main" function that lets you run them as a regular application; if yours does not you will have to write another Java class with a "main" function that creates a frame and starts the applet within it. If your applet code needs tighter integration with your MFC app than running as a separate Java process will allow, you might have to look at the JNI (Java Native Interface), or whatever the equivalent is for Microsoft's brain-damaged JVM, to incorporate the Java runtime into your application.

                    C Offline
                    C Offline
                    Crercio O Silva
                    wrote on last edited by
                    #9

                    Hi antlers, That sounds amazingly harder than I thought. Would you think it would be a better idea to use ActiveX controls instead of applets? Would the use of ActiveX controls present the same kind (or maybe different) of problems? Thanks a lot for your explanation. It helped me a lot to understand the process. Crercio O. Silva / DBTools Development http://www.dbtools.com.br

                    A 1 Reply Last reply
                    0
                    • C Crercio O Silva

                      Hi antlers, That sounds amazingly harder than I thought. Would you think it would be a better idea to use ActiveX controls instead of applets? Would the use of ActiveX controls present the same kind (or maybe different) of problems? Thanks a lot for your explanation. It helped me a lot to understand the process. Crercio O. Silva / DBTools Development http://www.dbtools.com.br

                      A Offline
                      A Offline
                      antlers
                      wrote on last edited by
                      #10

                      I guess ActiveX controls would work. You might need to have them installed along with the app on the machine instead of read from the resource file though. Microsoft wrote some extensions to their JVM that allow Java stuff to be accessed as ActiveX controls, and I suspect that doing this would be the least work for you (unless recoding the applets is really easy). I haven't used Java this way myself, but check http://www.codeguru.com/java/tij/tij0195.shtml

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups