Unable to access images from within a war dependency - java

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

Related

How to deploy a WebContent folder to tomcat?

I have a simple project in eclipse that only contains a WebContent folder with dynamic html pages (javascript, jquery, css etc).
How can I deploy such a project (that does not have a war file) to a Tomcat?
A WAR file is just a .zip with a different extension. You just need to make sure there is no top level folder within the .zip. Your files need to be in the root of the archive.
To deploy your static files you can either create a directory (the name of the directory will become the context path - use ROOT for the default web application) and copy your files to that directory. Alternatively, zip everything up, change the extension to .war and copy that to the webapps directory. The name of the WAR file (minus the .war extension) becomes the context path.
There are numerous edge cases and details associated with the above. For the full details, see the Tomcat docs:
http://tomcat.apache.org/tomcat-8.0-doc/config/host.html#Automatic_Application_Deployment including the links on naming and expected behaviour.

GWT: Loading an Applet inside an application

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.

How can i run the project which have folders like conf,css,html,js,jsp and WEB-INF?

I have one java web project folder and it contains folders like /conf, /css, /html, /js, /jsp and /WEB-INF.
/conf folder contains vestweb.cfg, *.css, *.html, *.js, *.jsp files.
/WEB-INF has /src folder and contains java source files(not able to find project to import.).
I could not find any root files(.war) in those folders.
How can I configure this folders to run the application?
If I understand you correctly, what you need to do is package the folder structure into a deployable package (exploded or compressed).
Compile the java source from "WEB-INF/src" folder and copy the class files to "WEB-INF/classes" folder
You can rename the root folder as "[YOUR_PROJECT].war" or you can compress it to a .WAR file
Deploy the package into any web-application server
Access your files from browser

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.

Categories