Can't deploy site on tomcat on mac - macos

I cannot figure out how to deploy a website (not app) on Tomcat on my mac. I just want to have Tomcat serve the file index.html. I tried creating the file myapp.xml in library/Tomcat/conf/Catalina/localhost with the content:
<Content path="/myapp" docBase="/Users/jerryk/Development/myapp" />
But when I attempt to access the site with
"http://localhost:8080/myapp" or "localhost:8080/myapp/index.html"
I get a resource not found error.
http://localhost:8080 brings up the Tomcat control panel.
Any thoughts on what I am doing wrong? FWIW, this works fine on windows.
Thanks,
Jerry

I'm not sure what's going on with Windows, but theoretically, the docBase must point either to a .war file, or a directory that has the same layout as a war file.
So, you can't just have an index.html in that directory, you also need at least a WEB-INF directory with a minimal web.xml in it.
See, for example, http://oreilly.com/java/archive/tomcat.html

Related

Running Spring application outside of an IDE (preferably OS shell)

https://www.pegaxchange.com/2018/01/24/java-web-project-with-spring-framework/ has instructions for creating a Java Web Project with Spring, without Maven. I am able to get it working in an Eclipse environment. It works as expected by doing “Run As” --> “Run on Server”.
When I kill Eclipse I get the Status 404 error (“The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.”). I have verified that the Tomcat Server is running from the XAMPP Control Panel.
How do I launch the application from an OS shell (Windows & Linux) so that I don't see the 404 error?
Its been a long time I haven't used java web projects without maven but if my memory serves me right, you should first export your project as .war file. Then deploy it to tomcat.
In eclipse right click your project select export and then select WAR file.
Copy your WAR file into webapps directory which is located in tomcat installation directory.
Rename the WAR file as you like if you want to serve you web app with a specific context name something like http://localhost:8080/myapp. If you do want to serve as root without a context name just rename it as "ROOT".
Run tomcat by command line <your-tomcat-installation-dir>\bin\startup.sh or it will be a .bat file for windows so you should end your command with .bat.
Or if you can start and stop by XAMPP panel this should do the same as well.
Also you can see this article for details on how to deploy a war file to tomcat.
I hope this helps. Cheers!

Tomcat context.xml from META-INF folder for context root configuration

I have an application which is being deployed in Tomcat 8. This application needs to be the context root.
To do this, I put a root.xml file in conf\Catalina\localhost folder and it worked.
Now, the problem is that when i debug through IntelliJ idea (Remote host) it is not being deployed as the root application.
Seems like the only way to fix this problem is to add context.xml file in META-INF folder and specify the configuration there.
Now, when I do this, context root configuration from context.xml file is not being picked up.
Any thoughts on this? Ultimately, I just need to debug the application through a remote server.

Same webapp on Tomcat with different log4j config for each

I've hunted and read, and I think there's no way...but just in case.
I need to deploy the same webapp to Tomcat multiple times, each with a different config that indicates which database to work with. I've figured out how to do that without modifying the contents of the war file.
In short, I copied WebApp.jar to WebAppDB1.jar, WebAppDB2.jar, and deploy these to the webapps folder, and use a custom context configuration for each in tomcat/conf/Catalina/localhost. So I'm good there.
But I would really like for each of these to log to a separate file. As it is, everything goes to catalina.out. It's a Spring app using log4j and slf4j. Every avenue I've explored gets me nowhere.
For now, I'm back to updating the actual war file, going into WEB-INF/classes and updating log4j.xml, but that makes it a manual process.
Any ideas?
You can put the log4j.xml files somewhere in the outside the webapp and use Tomcat's VirtualWebappLoader to load different log4.xml for each webapps.
http://tomcat.apache.org/tomcat-7.0-doc/config/loader.html#VirtualWebappLoader_Implementation
It looks like this.
${CATALINA_BASE}/conf/Catalina/localhost/WebAppDB1.xml:
<Context docBase="..." >
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/somewhere/WebAppDB1" />
</Context>
${CATALINA_BASE}/conf/Catalina/localhost/WebAppDB2.xml:
<Context docBase="..." >
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/somewhere/WebAppDB2" />
</Context>
And then put log4j.xml files into /somewhere/WebAppDB1 and /somewhere/WebAppDB2.
Hope this helps.

TOMCAT 7 not deploying war

I have developed a Dynamic Java Project with Eclipse which involves web services(RESTful). After completion I tried to run my project Tomcat 7 runtime of Eclipse IDE, it works fine. I am able to access all my web services.
But, when I created a WAR file out of my project by right-clicking on project and exporting it to WAR file and placed .war file in Tomcat 7's webapps folder. Started the tomcat by running startup.bat, it throws below exceptions and I am not able t access any web service:
I have placed all the required jar files in lib folder of Tomcat.
Exception fixing docBase for context [/Books] (Books is my war file name)
Failed to create work directory [{CATALINA_HOME}\work\Catalina\localhost\Books]
Failed to create destination directory to copy resources.
Could anyone please let me know what I am missing??
Thanks in advance.
Regards,
Piyush
The failed to create "work directory" error can occur if the work folder does not exist in the tomcat7 folder.
Also this error can be caused by tomcat not having sufficient permissions to read, write and execute in the tomcat7 directory.
The issue is because, tomcat is not finding your web.xml location in the classpath.
Do below steps:
Right click on web project-->Properties-->Deployment Assembly--> Add your classpath to web.xml(src/main/webapp) in my case.

Mapping a directory outside the web-app to URL in TOMCAT

I need to map an directory containing images which resides outside tomcat webapps folder, so that application can serve those images.
I am making a J2EE Web application running under tomcat 6. User can upload/delete images in the application. Currenly I store these images to a directory under application's WebContent folder, but I want to take it outside the tomcat (e.g. C:/test/images).
I need to know how to I configure tomcat so that if I access URL http://.com/images/abc.jpg , it serves the image from directory C:/test/images
Thanks,
Add a <Context> tag in server.xml, inside the <Host> tag:
<Context path="/images" docBase="C:/test/images/" />
Docs will be accessible at http://localhost:8080/images
in Tomcat8 you can also add PotsResources to you META-INF/context.xml as follow :
<Context>
<Resources allowLinking="false">
<PostResources readOnly="false"
className="org.apache.catalina.webresources.DirResourceSet"
base="path-to-your-local-folder"
webAppMount="/images"/>
</Resources>
...
</Context>
I had the same issue but found a solution.
If you are using Eclipse and a Tomcat plugin then please note that the Eclipse Tomcat plugin creates a separate CATALINA_BASE under the Eclipse workspace directory.
You can go to this location and you will find server.xml.
Use that server.xml and it will work.
My actual tomcat directory is:
C:\apache-tomcat-7.0.62x64\apache-tomcat-7.0.62\conf
and my Eclipse Tomcat server uses:
C:\workspace\JSF\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf
Use the workspace path and server.xml from this location.
Add this in server.xml inside the host tag:
< Context docBase="D:/personal" path="/images" />
and it will work if D:/personal has 1.png, and then the url http://localhost:8080/images/1.png will load the image.

Resources