I have quite an interesting issue. I'm running maven to compile my Servlet site into a single WAR File. This works completely fine on my local machine; and even when I change my deployment settings to use just the war file, it works fine. However, when I deploy the WAR file to the server, I'm getting 404 errors. I'm no expert with WAR files, so is there some sort of internal file that specifies the location of resources that I need to look at?
First try to unzip your war (wars, jars, ears are zip files) and see if your files are actually there, verify if your unzipped war contains:
dir WEB-INF
file WEB-INF/web.xml
dir WEB-INF/lib with the jars your aplication depends on
dir WEB-INF/classes with *.class files, where your servlets and related classes are supposed to be (if you have decided to have them there and not in a jar in WEB-INF/lib)
static resources in the root directory
You could make your conclusions of what is missing in your war.
You could also try to build your own war manually (creating a zip file with the structure I mentioned above and renaming it as *.war) if you have problems with doing it by your IDE's options
Related
I have WAR file that contains symlinks for certain libraries.
When I extract the war file into webapps folder using unzip command it creates the symlink properly and web app loads without any issues.
However when I place the WAR file in webapps and let Tomcat deploy it , the symlink becomes a simple text file.
How do I overcome this situation, is there a way to customize the WAR explosion process.
EDIT
I suspect this is because Tomcat user Jar command to unpack a war file, is there a way to make tomcat use unzip command instead?
I have a war file, this war contains multiple jar files. Now my requirement is I have another war file which has dependency on jar files of first war. So Could any one help me how to refer the first war's jar files in MANIFEST file of the second war.
I think you can deploy those WARs in an EAR, and put the common resources in the EAR. Then you can update the manifest in each WARto use the resources in the EAR.
First of all, interdependent WAR applications that are not a part of the same EAR, sound like an awful idea. With that said, nothing is preventing you from extracting the common jars into application server's lib directory. But, why wouldn't each application contain it's own dependencies?
I've read somewhere as a good practice, that it's better to have the required libs included in each project, then just add all the libs you'll ever need to the tomcat folder. Well right now Tomcat seems to need all the required libs to be in lib folder of Tomcat. How can I make it use the libs from the build path of the project? i'm using tomcat 7.032 in through Eclipse.
The libraries of a webapp must be in the WEB-INF/lib directory of the deployed web application directory or war file.
Every jar file in this directory will be in the classpath of the webapp, and won't be in the classpath of the other deployed webapps. You indeed shouldn't put webapp libraries into Tomcat's classpath.
So I was given a WAR 'file', but upon downloading it I noticed that it is actually a folder, not a WAR file. Trying to open this folder in Netbeans is not working, because it is expecting a war file, not a folder.
I attempted "War-ing" the folder, which worked. Netbeans can now open the file, however none of the files can be edited.
This was tested using apache's ode.war in NetBeans 8.0:
Unzip the war file
In the unzipped folder, you will see WEB-INF/, META-INF/, etc., create a sub-folder named web in the unzipped folder.
Put everything else into web (now they will be web/WEB-INF/, web/js/, ...)
Go to netbeans, new project -> java web -> web application with existing sources
Pretty much just press next all the way through. voilĂ , it's done.
If you don't have eclipse handy, just place the war file into the webapps folder of Tomcat, go to the bin folder of Tomcat and run startup. Tomcat will automatically extract the war file for you. Now go to the webapps folder and you'll find another folder there, with the same name as your war.
I couldn't find an option to import a war directly into Netbeans (strange. Perhaps someone could create this feature and submit it as a patch to Netbeans). The folder which gets extracted into the Tomcat folder can be used as the Netbeans project. It's advisable to copy it to some other folder first. Import by File > New Project > Web application with existing sources.
Eclipse has an option to export a war and include the sources with it too, so there's a chance that the source files are in the war too.
I use the jstl library in my project, but as an external jar. After exporting my project to a .war file, these libraries are not included and I'm getting errors. How do I make sure the library is included in my war file?
Also, an unrelated question, if an ear file would have only one war module, is there a point to making it an .ear instead of .war
If you have put the jstl jars inside WebContent directory they will be packed in your WAR file. But if you are loading them from somewhere else make sure that you have them in your export list (Project Properties -> Java Build Path -> Order and Export).
If you have an EAR file you can make some extra settings in your application.xml file, or even some container specific ones.