Applet war project doesn't find applet class in jar - java

I have the following projects
>projectJar
>projectWar
Inside projectJar I have a class that extends Applet, the class's name is com.me.test.TestApplet. Then in the war project I include the jar and create an HTML file like the following...
<HTML>
<HEAD>
<TITLE>A Simple Program</TITLE>
</HEAD>
<BODY>
<APPLET code="com.me.test.TestApplet.class"
archive="WEB-INF/lib/projectJar.jar" WIDTH=256 HEIGHT=240> </APPLET>
</BODY>
</HTML>
However, when I try to load the applet I get a class not found exception for TestApplet. Can anyone see what I am missing?

You cannot serve a "PATH" under "WEB-INF". Move your "projectJar.jar" to another folder, perhaps "/jar/porjectJar.jar".

Related

I want to put my jar file in html code

How can I put my jar file into my html?
I tried to use that:
<html>
<head>
</head>
<body>
<applet code=Tictactoe.class archive="Test.jar">
</applet>
</body>
</html>
My problem is that when Im trying to run my html code java is blocking my jar file.
Try to add your url (local or distant server url) in exception list on java settings panel.

ClassNotFoundException Java Applet

I get the ClassNotFoundException error when I make my html file with the code and jar file. Not sure why. Here's what I have:
<html>
<head>
<title>
Test Applet
</title>
</head>
<body>
<h2>Test Applet</h2>
<applet
code="Testing.class"
archive="myTestJar.jar"
width=550 height=300>
</applet>
</body>
</html>
I simply have the class in a jar file and tried to reference using archive but it doesn't work.
try this
<applet code=Testing.class
archive="myTestJar.jar"
width=550 height=300>
</applet>
The class has your main() I assume, the jar is the entire thing.
if,you're not taking packages into consideration. For instance, if the package is myPackage.vol3 then the line should read
<applet code="myPackage.vol3.Testing.class" archive="myTestJar.jar"
and put the html file in the project folded "INSIDE" the project folder.

Class not found exception Applet.jar in html file

I am trying to run an .jar file with a class in it that extends Applet in an html file. The .jar is called DocScrabble.jar, html is DocScrabble.html, and .class file is ScrabbleSolver.class. ScrabbleSolver.class also references a file called EnglishWords.txt, and I included that in the default package in which I placed ScrabbleSolver.class when I exported the file to a .jar. DocScrabble.jar and DocScrabble.html are located in the same directory. The applet works fine in eclipse, so I am assuming that my html file is the problem. THere is the html code.
<!DOCTYPE html>
<html>
<head>
<title>Doc Scrabble></title>
</head>
<body>
<APPLET CODE="ScrabbleSolver.class"
ARCIHVE="DocScrabble.jar"
WIDTH="400"
HEIGHT="200"
</Applet>
</body>
</html>
When i try to run the html, it gives me an error that says ClassNotFoundException ScrabbleSolver.class. Could someone please tell me what's wrong? I'm relatively new to programming.
It is highly advisable to check HTML using a validation service or DTD.
I typically rely on the W3C HTML validation service to check HTML.
Note that the applet element was last valid in HTML 3.2. It was deprecated in HTML 4.01. Without declaring any version, that mark-up would be presumed to be HTML 5.
The best way to deploy an applet is to use the Deployment Toolkit Script. On the other hand mistakes in spelling the attribute names in the script would not be picked up by an HTML validation service, since it concentrates on the HTML, rather than JavaScript embedded in the HTML.
For that reason it is a good idea to see the applet work when loaded using 'pure HTML' first.
Is your ScrabbleSolver class in a package? if so then it should be packagename.ScrabbleSolver.class
See Also: http://download.java.net/jdk8/docs/technotes/guides/jweb/applet/using_tags.html

Where I save the applet in tomcat?

I call an applet through a JSP...where I have to save it? and what the .class and the .java file? in which root in tomcat so when I call it from the JSP to be appeared?
here is the applet call from the jsp
%><%# page language="java"%>
<html>
<body>
<jsp:plugin code="g7appletDialog.class" codebase="" type="applet" width="300" height="200">
<jsp:fallback>Unable to load applet</jsp:fallback>
</jsp:plugin>
<applet code=""g7appletDialog.class"" width="300" heigjt="200"></applet>
</body>
</html><%
The path to your servlet must be relative to your jsp. If you have a jsp in web-inf/admin/pages/index.jsp, then you can place the .class file in directory web-inf/admin/pages/ and just have code="g7appletDialog.class".
In case that you have a central repository for applets, lets say web-inf/admin/applets then you should change the code to code="../applets/g7appletDialog.class".
The ../ gets you one dir back. To go two dirs back use ../../ and so on...

How does HTML java applet finds its .jar?

I have this code:
document.write("<APPLET CODE='com/synergex/My.class' ARCHIVE='toc2.jar' ");
When my "toc2.jar" is in the same folder as the HTML - all works fine.
But when I put "toc2.jar" in another folder ("C:\MyJars"), I get ClassNotFoundException.
How can I "tell" the browser where to look for jars?
I tried to add "C:\MyJars" or "C:\MyJars\toc2.jar" to my CLASSPATH env variable, but it did not work.
You might be able to redirect the code base using an HTML base element.
For example, given the following BASE declaration and A declaration:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Our Products</TITLE>
<BASE href="http://www.aviary.com/products/intro.html">
</HEAD>
<BODY>
<P>Have you seen our Bird Cages?
</BODY>
</HTML>
the relative URI "../cages/birds.gif" would resolve to:
http://www.aviary.com/cages/birds.gif
If not, there are only 2 options.
Leave the Jar in the same directory as the HTML.
Presuming that part of the script is the only thing you cannot change, add codebase='../path/' immediately after it, to tell the JRE to wherever the Jar is located.
As an aside:
CODE='com/synergex/My.class'
Should be:
CODE='com.synergex.My'

Categories