Applet on Website seems to hate Packages - java

So I made an Applet (not JApplet) and proceeded to upload it to my website. I put all of my .class files into a package, exported the project from eclipse to a .jar, and uploaded that to the public_html folder of my website.
In my HTML code, I put
<applet ARCHIVE="BallShooter.jar" CODE="BallShooter" width=500 height=500> </applet>
However, it seems that I kept on getting the error "ClassNotFoundException"
If I reupload the .jar WITHOUT the package, it worked fine. Could somebody please explain to me how to fix this?
For those who are wondering, this is the structure of the things in the website
/public_html/myAppletJar/myPackage/a.class
/public_html/myAppletJar/myPackage/b.class
/public_html/myAppletJar/a.png
/public_html/myAppletJar/b.png

Check all these points:
if the applet class is BallShooter, and is in the package kikiotsuka, then its source code must start with the line package kikiotsuka;. The full name of the class is thus kikiotsuka.BallShooter.
in the jar file, you should thus have a directory named kikiotsuka at the root, and this directory must contain a file named BallShooter.class
since the name of the class is kikiotsuka.BallShooter, that's what the code attribute of the applet HTML element must contain: code="kikiotsuka.BallShooter" width=...

Related

Jar Applet in HTML

I've seen topics like this alraedy, but its not working for me.
So I have a game that succesfully made into an applet and it has many classes that are in a package called Build9. I want to put it on my website.
My file structure is the html file in the root "Desktop/My Name" and I have a media folder that has the RomanFury.jar.
I've tried every combination of changing around the code and archive in the HTML tag. With the classic:
<applet code="Main" archive="RomanFury.jar" width="1280" height="720">
My game.
</applet>
I get an error that says it cannot find Main. If I put media/RomanFury.jar or put media/ infront of main the same kind of error is given.
Can someone tell me the correct html tag?
My .class files are in a folder called "Build9" in RomanFury.jar.
Based on the information provided, this
<applet code="Main" archive="RomanFury.jar" width="1280" height="720">
should be
<applet code="Build9.Main" archive="RomanFury.jar" width="1280" height="720">
because your game has many classes that are in a package called Build9 (and your .class files are in a folder called "Build9" in RomanFury.jar).

How to save code for Java applets

I am thoroughly confused as to what part of my code I need to put onto a website in order for me to embed this as a gadget in Google Sites. One source that I found said that I should have both my main class as one file and my whole project as another. I am using Google Code, and have gotten my main class (which is saved as a .java file), and the rest of my project (which is saved as a .jar file) onto the code file cabinet.
Currently, I am getting an error with my code not being able to find the class that contains my main(String[] args) {} method. Officially, it is a ClassNotFoundException, with the text Main.java, which is the name of my 'code' in HTML. If you want to see it for a reference, here is the HTML that I am using for my Google site:
<applet name="UnderLD" code="Main.java" archive="UnderLudumDare.jar"
codebase="http://wierd0games.googlecode.com/svn/"
width = 300 height = 168>
Sorry, this Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)
</applet>
However when I paste the link for the codebase in my brower, the java.Main class (the one with my main method) is the first on the list. To me, I am doing everything correctly according to all of the tutorials I have found, so what am I doing wrong?
code should be the name of class file for the applet, not the name of the source file. The trailing .class is optional but Sun now recommends omitting it. All of the main browsers will work with or without the .class suffix.
So both of the following should work, provided Main.class is in the root of the jar file:
code="Main.class"
code="Main"
Source Using applet, object and embed Tags
code = appletFile
This required attribute gives the name of the file that contains the
applet's compiled Applet subclass. This file is relative to the base
URL of the applet. It cannot be absolute. One of code or object must
be present. The value appletFile can be of the form classname.class or
of the form packagename.classname.class.

Error called"NoClassDEFFoundError "comes when running a applet

Hey guys i have a problem that has been wasting my times for hours which is that i get an error saying "NoClassDEFFoundError Wrong name(bigFish/BigFish)" when i try to run my html file which include a class and that contains a applet. bigFish is my project name and package name. BigFish is my class name of the class which contains the applet. and i have located my html file called BigFish in where the BigFish class file is located. how to do this. this comes in firefox. and i can't shift to chrome. its not working since month a back(doesn't even open). how can i see my applet run on web?
..i have located my html file called BigFish in where the BigFish class file is located.
That probably won't work. A loose class file in the bigFish package needs to be in a similarly named directory of the server. So, assuming the HTML is in directory www on the server, the structure should look something like this:
www directory
bigFish directory
BigFish.class
BigFish.html

Error in running applet in appletviewer: NoClassDefFoundError

I just ran into trouble in applet execution in webpage:
An error dialog popped up:
calculator is my class name and Exercise4 is the folder that contains it. I am sure that the html file and the calculator.class are in the same folder named Exercise4. What is happening in here?
I am sure that the html file and the calculator.class are in the same folder named Exercise4.
That would be a problem. The HTML needs to be at the root, not inside the 'package' directory.

How to use an applet with packages in a jar

I have an applet (Applet, not JApplet) that has a lot of classes organized into packages, including the applet itself. I have looked everywhere for how to use that jar as an applet. It is not runnable and has a manifest file like such:
Manifest-Version: 1.0
Class-Path: AppletSource.jar
I put it in an html (Game.html), as such:
<applet code="Game/Game.class" archive="Game.jar" width=800 height=600>
Your browser needs JAVA!!!
</applet>
As you can see the class is called Game.class, Package Game and the jar Game.jar.
The manifest is in Game.jar/META-INF
When I use the appletviewer Game.html I get an error (java.security.AccessControlException: access denied) and if I open the .html I get a ClassNotFoundException: Game.Game.class. What can I do?
try
<applet code="Game.Game" archive="Game.jar" width=800 height=600>
Your browser needs JAVA!!!
</applet>
Also check that the package name is really Game and not game.
The format for the applet code attribute is from oracle doc "The value appletFile can be of the form classname.class or of the form packagename.classname.class.".
This file is relative to the base URL of the applet. It cannot be absolute.
Also try adding the jar in the same directory as the html.
For some further information see this doc
http://docs.oracle.com/javase/1.4.2/docs/guide/misc/applet.html

Categories