Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Applet jar will not load. Peculiar.

 
Ranch Hand
Posts: 163
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I frequent these forums for research and I strive not to take advantage with questions that can be answered with a little research. Unfortunately, I'm at an impasse and could benefit from any knowledge you have.

I'm building my first JApplet, and it unsuccessfully loads with the inevitable "Incompatible magic value 171733859".

Here's what I've researched, discovered, tested:

1) https://coderanch.com/t/541772/Applets/java/getting-APPLET-tag-work#2457961

Paul Clapham wrote:No, it's clear that the browser's Java support is finding your class file just fine... it's complaining about its contents.

The "magic number" it's complaining about is the first four bytes of the class file. Those bytes are supposed to contain a specific set of values (actually "CAFEBABE" in hexadecimal), but they don't. What you see in the error message is the decimal value of the magic number; 1008813135 decimal is equal to 3C21444F in hexadecimal.

And when you look at an ASCII table, you can see that 3C21444F hexadecimal corresponds to the four characters "<!DO". And that suggests to me that what the browser is downloading from your so-called "class" file is actually some kind of XML or HTML document which starts with a DOCTYPE. So put your actual compiled class file there instead.>



I translated my magic number, 171733859, to hexadecimal, 0a:3c:73:63, to ASCII, "?<sc". To the best of my knowledge, I do not have any document, xml or otherwise, in my webapps directory that starts with "?<sc". To verify, I ran 'grep -r "?<sc" *' and it returned nada.

2) I focused on a working applet, to eliminate the possibility that my applet is in error. I deferred to Java's twirling mascot applet. This applet loads and runs from Oracle's URL without any problem.

I downloaded the applet's jar and placed it in my webapps directory. I also borrowed Oracle's applet tag and placed it in TumbleItem.html:



NOTE: I do not have a directory for images/tumble. I didn't feel it was necessary as parameters shouldn't prevent an Applet from loading.

3) In my Tomcat webapps, I created the subdirectory "civil/applet" and stored TumbleItem.jar and TumbleItem.html.

4) Here is the Java 1.6.0_31 Console Log:



I'm particularly interested in this snippet:



The URL is correct and verified. I can go to URL "http://vesta:10074/civil/applet/TumbleItem.jar"; and I will be prompted to save the jar file. The file size of the downloaded JAR matches that of the one on my server.

The Content-Length is not correct. The TumbleItem JAR is approximately 59K.

5) I verified the permissions on my webapps directory with a simple test. I put a GIF file in my civil/applet subdirectory to see if I can pull it up in my browser. It worked.

6) https://coderanch.com/t/480492/Applets/java/Tomcat-JSP-Applet#2155656

Ulf Dittmer wrote:Try removing the codebase attribute.



I removed the codebase attribute. No effect.

7) I cleared my cache in the Java Control Panel. No effect.


So, that's where I am. I'll update this thread with any new leads, or if I solve the problem (fingers crossed).
 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it working. Took some trial and error though.

1) I simplified things even further by borrowing Oracle's simple "Hello World" Applet. This jar file contain only the .class file and no subdirectories.

Running this applet resulted in the same error.

2) Another google page (sorry, don't have the link) said that applets need to be publicly accessible by the browser. THIS is my culprit.

My /civil/applet folder on my Tomcat webapp was not public. It was restricted by default and I never thought about it's permissions. Giving it public access resulted in a happy "Hello World" applet.

Problem solved.



 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for posting the solution.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic