package com.x.y.z does not exist - java

I'm trying to run old servlet under resin. I have deployed it as a war file. After starting resin there is a dir ic. It contains Webcontent dir with WEB-INF/lib/ic.jar (fatjar), jsp etc. While extracting this ic.jar I see there package com/x/y/z but while trying to access servlet page I'm getting an error: package com.x.y.z does not exist.
Can anyone give me any clue?

The jar needs to be in WEB-INF/lib, not in WEB-INF.

When extracting the JAR file, you should see
com/x/y/z/ClassName.class
not
com.x.y.z/ClassName.class
Assuming that what you wrote wasn't a summary of what you saw (or a typo).

Related

Why doesn't tomcat see certain folders?

In my tomcat webapps directory I have various projects with servlets in them ..
say named test,beer etc
My question is irrespective of the web.xml or contents when i type localhost:8080/folderName I must be able to view the contents right? but it doesnt work for all folders , for some it says resource not found ,
Example my test folder opens in the browser and my beer folder doesnt , I restarted the browser and tomcat after adding or modifying folders , why can this happen , please explain
My dear friend there is a certain process/configuration/rule that tomcat follows in order to render any web content.It is not some magic happening.
Tomcat has a way of reading web deployments within the /webapp directory.
When we type some URL On the browser tomcat does the following:
Example.
URL : http://localhost:8080/foldername/xyz
Here tomcat takes the part of the URL after http://localhost:8080,that is foldername/xyz.
So here the first part which is foldername means name of the folder present in the /webapps folder.
So reading this tomcat goes inside that folder.Later tomcat is at the mercy of a file called web.xml.All mapping from /foldername/ i.e. /xyz in our case, onwards are present in web.xml.
In your case , if you type http://localhost:8080/foldername/ , tomcat knows that browser refers to webapps/foldername but does not know which resource html/jsp/servlet to forward the request so as to be able to generate a response.
Hence it gives a resource not found exception.
If you want to run the above URL (http://localhost:8080/foldername) then you need to configure a <welcome-file-list> tag in the web.xml file.
So for the folders which are working in your case with the above URL, just open their web.xml file and you shall find the <welcome-file-list> tag.
Actually this is what happened
I had a folder test which had some files (NO WEB-INF) , tomcat listed its contents on typing localhost:8080/test
My other folder beer had a WRONG WEB-INF web.xml configuration
So the following is clear to me now
Without a WEB-INF folder and web.xml tomcat will just list the contents of the directory but when you have a WEB-INF and web.xml and something is wrong in them it doesnt even list the directory contents .
Just my understanding of it .
Thanks!

The tag handler class for "c:url" (org.apache.taglibs.standard.tag.rt.core.UrlTag) was not found on the Java Build Path

<c:url var="addAction" value="/user/add"></c:url>
warning:The tag handler class for "c:url"
(org.apache.taglibs.standard.tag.rt.core.UrlTag) was not found on the
Java Build Path
I have included the JSTL jar but still it gives same warning.
Is any other jar required?
You have to add standard.jar as well.
Did you include the jar files into the correct directory?
They need to be stored in the lib folder in WEB-INF (...WebContent/WEB-INF/lib/).
You may have just stored them in the WEB-INF folder.

Load config file from a war

I have a Maven project that I'm trying to package as both a war and a jar. As part of my application / servlet initialisation (depending on whether I'm running the jar or the war), I need to read a file called server.ini. I've put the file in src/main/resources/server.ini and am trying to load it like so:
System.class.getResourceAsStream("server.ini");
However, this always results in null. What am I doing wrong?
The server.ini file should be in the root of a resources directory.
By placing it in the webapp you're making the file available via http, but you need it accessible on the classpath, which means that you should place it in the resources directory.
There's a good chance web.xml or context.xml is better suited to what you're trying to do, but...
Try putting server.ini in WEB-INF/classes, or do something like this.
The issue was that I was using the System classloader with an unqualified path, so it was expecting to find my server.ini in the java.lang package.
Since my file is in src/main/resources, I should just use the classloader of my current class, with an absolute path:
getClass().getResourceAsStream("/server.ini")
This works in both the war and the jar.
The "Preferred way of loading resources in Java" question has a great explanation of resource loading.

How to read a directory in webapp folder of Maven web application

I'm working in maven web application. I need to read a directory(For ex: Files) in my webapp folder as follows,
Java.io.File file = new Java.io.File("path");
But I don't know how to specify the path of the directory here.
You shouldn't give local path addresses. Path should be a relative address, e.g. /files/images under your web archive (.war) folder.
To use relative paths properly, I suggest you to add your target folder to the resources definiton of POM.xml, check out these pages
http://www.mkyong.com/maven/how-to-change-maven-resources-folder-location/
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
You can refer to resources folder easily with something like this:
this.class.getResource("Mydirectory/SubDirectory");
When in doubt how relatives paths work, it's always best to do something like that:
System.out.println(new File("/my/desired/directory").getAbsolutePath());
This will print out the path in which classpath will look for the files.
Assuming:
servlet container webapps dir is located in: /var/lib/tomcat6/webapps
your webapp is called my-webapp.war
You should see the following output: /var/lib/tomcat6/webapps/my-webapp/my/desired/directory
Another pointer: you have mentioned that you are looking for webapp directory. I hope you know that this directory will not end up in *.war - it's contents will.
War files are not always expanded when they are deployed to an app server, so it's possible that a relative path won't exist in a filesystem at all.
Best bets are to use getResource from the class loader, which will return things in the class path (the WEB-INF/lib directory, etc), or to use the getResource() method of ServletContext to find things in the web application itself.

directory structure in Tomcat 5(s)

I was wondering if it was possible to maintain a directory structure within the application folder in side webapps folder, i.e. I have created a folder called ITC357, which acts as my application folder which carries all my files, so the directory path is as follows:
C:/Program Files/Tomcat5/webapps/ITC357
I'm doing an assignment and I would like to deploy that ITC357 in a separate folder can I do this? if so how?
It is not clear what you are asking:
If you asking if it is possible to have directories inside C:/Program Files/Tomcat5/webapps/ITC357 then the answer is "Yes".
If you are asking if it is possible to put your webapps file in a separate directory then the answer is "Inadvisable". The tomcat framework looks for certain files within the webapps/<name> tree; e.g. a context.xml file, a web.xml file, classes / JARs, etc. You could code your servlet to look for other things in other places, but this causes various problems with deployment (and undeployment) and security.
If that doesn't cover it, please clarify your question.
If you are writing JSPs, then the URL of the JSP will include any subdirectories that you create. So if under ITC357 you create a subdirectory called "foo", and in that subdirectory you have a JSP called "bar.jsp", and your context name is "plugh", then the URL of that JSP will be "http://whateverserver.com/plugh/foo/bar.jsp".
If you are using servlets, then it is up to your code to decide what to do with any URLs passed to it. You could map "http://whateverserver.com/plugh/foo/twisty.do" to "c:/program files/tomcat5/webapps/ITC357/WEB-INF/classes/foo/twisty.class", or you could map it to someplace totally different. (I prefer to map to a package name that matches the URL unless there's good reason to do otherwise.)

Categories

Resources