GWT: Loading an Applet inside an application - java

I am trying to integrate an existing applet packaged as jar file in an existing GWT application built with maven.
Now I am not being able to figure out, why the applet class is not being found. A ClassNotFoundException is being thrown when I try to load the applet, saying that the applet class cannot be found.
The GWT Maven project has several modules and the applet I want to integrate is in its own Maven module.
The applet jar file is being signed and packaged as in the final war file for the GWT app by the maven build process.
When I deploy the war file in a Tomcat server I have the following structure under the webapps folder:
webapps
my_gwt_app
WEB-INF
classes
deploy
lib
signed_applet.jar
other_application_dependency.jar
views
web.xml
Here is the HTML result which is being generated by my GWT presenter:
<applet code="com.example.MyApplet.class" archive="/my_gwt_app/WEB-INF/lib/signed_applet.jar" width="1000" height="800" id="my-applet">
<param name="permissions" value="all-permissions">
</applet>
Could someone tell me what I am doing wrong?
Thanks!

Nothing in the lib or classes directory is available to be served to clients that visit the site. It will be necessary to move the Jar to another place on the server.
In addition to that:
The following path is simply wrong.
archive="/my_gwt_app/WEB-INF/lib/signed_applet.jar"
WEB-INF would typically be the 'root' of the site.
<param name="permissions" value="all-permissions">
Whatever you are trying to achieve there, it will not add permissions to the applet.

I added the "applet" folder under the root folder (http://dev-server.com:8080/my_gwt_app/ not under WEB-INF) and called the URL "http://dev-server.com:8080/my_gwt_app/applet/signed_applet.jar" in the browser. The jar could be found.
But when I configure my applet like
<applet id="my-applet" width="1000" height="800"
code="com.example.MyApplet.class"" archive="../applet/signed_applet.jar">
</applet>
I still getting the ClassNotFoundException.

My problem was the jar file path configuration.
I put it in the my_gwt_app/gwt_module/applet directory and configured the applet with this jar path.
Now it works fine.

Related

java applet ClassNotFoundException with codebase

I'm starting to work on an applet that will replace an existing one. Having never developed an applet before, I thought I'd get going with the popular HelloWorld example. I am able to run it a couple different ways: in the appletviewer, and also in a browser if I put the JAR file containing the HelloWorld class in the same directory as the HTML (i.e. http://localhost:8080/myApp). I also got it to work when I put the JAR in a directory called HelloWorld just below the myApp directory and specified the codebase parameter in the <applet> tag as HelloWorld. But when I try to specify WEB-INF directories such as classes or lib, I get a ClassNotFoundException. What am I doing wrong?
But when I try to specify WEB-INF directories such as classes or lib, I get a ClassNotFoundException. What am I doing wrong?
Those directories are only meant for classes/jars that are used in JSP and servlets (i.e. the stuff the server needs). The resources inside them are available to site visitors. In this sense 'visitor' means a User Agent (i.e. a browser) or a client side plug-in (such as Flash or the JRE).
You can confirm this for yourself by pasting the full URL to the Jar in the web browser address bar and hit 'enter' to browser to it. The server will give a message back to the effect 'forbidden'.
See also the WEB-INF info. page which expands:
WEB-INF is the name of a folder found in Java web applications. It is used to store deployment information such as the web.xml, required library files and compiled class files. It is normally not accessible from web. Any files which you want to put on war but do not want to make to public then web-inf is the place where you can keep those files.

Unable to access images from within a war dependency

I am building a maven web project which has dependency on another war.
The problem is that, code inside the war(dependency war) is unable to access images present in this war(dependency war)
for example,
inside the war there is an image tag accessing the image as
"/static/images/tick.jpg"
http://hostname:port/static/images/tick.jpg <---Unable to access
It works when i try to access image as
http://hostname:port/images/tick.jpg <---Able to access
I cannot change the code inside the dependency war.
The directory structure is:
-target
-m2e-wtp
-overlays
-static.war <---- dependency
-images
-tick.jpg
-META-INF
-WEB-INF
-my project
-images
-tick.jpg
-META-INF
-WEB-INF
-war
-work
-com.portal.webapps
-static
-images
-tick.jpg
-my project.war <----war file
What am I doing wrong? Do I need to somehow specify where the resources should be deployed? If yes, how?
IDE - eclipse
Server - Tomcat

web.xml configuration for JSP

This is the structure of the JSP app on eclipse.Once I run it on eclipse using tomcat server(localhost:8090/index4.html) it works.On the index page i have to add details,this details are uploaded via the servlet as you can see above Java Resources->src->FileUPloadDBServlet(Also I am not sure if it uses this or it uses WEB-INF->src->FileUploadServlet below.)
In my index4.html the action is action=uploadServlet(no address given for it).This everything works on using eclipse.
But once I put the QMS folder(not WAR) from eclipse worskspace to tomcat ROOT,the index4.html works but the following action,i.e uploadServlet doesnt work(here I use the address localhost:8090/WebContent/index4.html)I dont have a web.xml.
Is that creating a problem?
Please provide me help.
You need to put your project folder or .war file in the
webapps folder of Tomcat directly not in ROOT folder under webapps.
Try to follow directory structure as follows
Photo Courtesy http://www.studytonight.com/servlet/steps-to-create-servlet-using-tomcat-server.php (Here you can also find more details on Servlet and JSP, as well as project structure)
Where you have your web.xml put into the WEB-INF folder under your application folder.
For java files you don't need the source files, the classes folder will have all the source folder (src) files compiled and ready to execute.
The lib will contain all the .jar files you need for your application to run.
Make sure you put web.xml file at proper place, because without it, application will not be able to run. Because as they say web.xml is Heart of the application.
Let me explain you the problem.
When we configure a dynamic java project to run on eclipse the server takes the just the stuff from webcontent folder and deploy it the wbcontent folder contains web.xml file which defines the url descriptor for servlet.
now when you copy the whole folder the server can not find the web.xml file which is a descriptor where it expects the file to be.
hope its clear comment for clarification

Where to put jsp project folder in tomcat for hosting?

I am right now working with JSP and using tomcat Apache for that.what my problem is when i am creating one single JSP page and putting in root directory of tomcat then its working fine.but now i have one project that contains some useful jars and other java classes so how to put that whole project directory in tomcat.
I had put that in web app directory but its giving me error as follows
The requested resource (/dailymotion-cloudkey-java-73f6f35/examples/upload.jsp) is not available.
I am Giving snapshot of my web app folder where i had put this folder name as dailymotion-cloudkey-java-73f6f35
i know that i am doing mistake while putting dailymotion-cloudkey-java-73f6f35 directory in tomcat.
but i am totally new in this so i couldn't find out so can anyone tell me
tree Structure of my project
I think dailymotion-cloudkey-java-73f6f35, does not have WEB-INF folder with web.xml file. Due to which it is not able to locate the resources.
or
You can copy your dailymotion-cloudkey-java-73f6f35 project directory into ROOT folder and then try the same URL.
Put it anywhere, but put a context file for your webapp to TOMCAT_HOME/conf/Catalina/localhost which points to for webapps's directory with the docbase attribute. Read details here.

Applet in Google App Engine

My aim is to host my applet to google app enigne.
I have made a jar of my applet, I have placed the jar into WEB-INF/lib directory but still when I write applet tag in my jsp page as
<applet code="myPackage.MyClass" archive="myapplet.jar" width="600" height="480"/>
The applet is not showing in the browser.
I am using eclipse with GAE plugin
Please Guide me.
Try puttIng the JAR into the same directory as the JSP file.

Categories