I have this directory structure in Tomcat: /webapps/webserver/warfile
When I try to start Tomcat, it can't look to the subfolder webserver and thus read the WarFile. If I change the directory structure like this: /webapps/warfile, everything works fine and I can access my application.
I know it would be easier if I just move the war file to the webapps directory, but it is a long story why I need in this way.
You can probably try changing base directory for deployment
Find server.xml at $CATALINA_BASE/conf/server.xml
Then, change appBase to your required path.
Please refer Apache Tomcat 8 Configuration Reference
Related
My java application has more versions of external context.xml, one for each environment. The plan is to have one war file and using the right context.xml for production, staging, dev, etc.
I currently copy/symlink the context.xml into /usr/local/apache-tomcat-7.0.72/conf/Catalina/localhost/myapp.xml. Then I create war file from my sources and I copy it into /usr/local/apache-tomcat-7.0.72/webapps. The catalina is running and explodes the war file in webapps folder. In the same time it deletes my myapp.xml from conf folder. For that reason my app doesn't load the proper configuration and fails. If I copy again the myapp.xml and restart tomcat it works.
Is there a way to tell tomcat to not delete my conf file when extracting war file? Or is there a better place for external context.xml
I guess you have some params in this context.xml for production or stage etc. It's not a good idea to store them there as better approach is to start server with properties and read them in webapp so you never make mistake a.
Look here: https://eureka.ykyuen.info/2009/12/15/tomcat-setting-java-system-properties-for-webapps/
I'd like to create a desktop standalone application from my Java/Spring web application. I created MSI-installer that copy all required files to C:\Program Files (x86)\App. But tomcat doesn't have permission and can't write to its own folder. How I can configure tomcat so it would write all app-specific data to other folder? I wouldn't like to install my app to C:\App or user dir.
java.io.FileNotFoundException: C:\Program Files (x86)\App\tomcat\logs\catalina.2016-06-18.log (Access denied)
By setting the environment variable CATALINA_BASE to another directory in your tomcat start script you can configure Tomcat to read/put the working data, configuration and stuff from/to another location. If CATALINA_BASE is set, Tomcat will use the folders %CATALINA_BASE%/bin, %CATALINA_BASE%/conf, %CATALINA_BASE%/logs, %CATALINA_BASE%/temp, etc. for the current instance of Tomcat. This is described in more detail in the Advanced Configuration - Multiple Tomcat Instances section of the RUNNING.txt file in Tomcat's root folder.
If you are planning to ship Tomcat with your application and put all Tomcat files to some user choosable folder you should set CATALINA_HOME to this folder. Tomcat will then use this folder as base directory for everything.
However I think, as you mentioned to ship a standalone application based on Spring, you should seriously take a look at Spring Boot. This will allow you to ship a single fat jar containing all of your application's dependencies (including Tomcat). And this application can simply be started by executing the jar file.
If it's just about the log and temp files, you can set the Java system properties java.util.logging.config.file and java.io.tmpdir in the setenv.bat file under %CATALINA_BASE%/bin to make Tomcat use a custom logging configuration and a different temp dir, respectively. That is the file would look something like this:
set CATALINA_OPTS="-Djava.util.logging.config.file=file:///c:/path/to/log/config.properties"
set CATALINA_OPTS="%CATALINA_OPTS% -Djava.io.tmpdir=c:/path/to/temp/dir"
Find and update all occurrences of "$CATALINA_BASE"/logs/catalina.out to custom path in catalina.sh script.
Question 1: May I ask what is the difference between deploying a java webapp with it's WAR file vs just copy/pasting the build folder into tomcat webapp folder?
Question 2: Somehow I am told to deploy my project just by renaming my /build/web folder to /build/, then copy and paste this folder into tomcat/webapp folder. Tomcat did serve the web app and I could access it via url. But the problem is that I suspect my System variables were not set. I start up a servlet and put this code in this init(ServletConfig config) method:
System.setProperty("LogPath","D:/Test/logs");
And doing this in my log4j.properties
log4j.appender.file.FILE=${LogPath}/wrapper.log
wrapper.log is not found in the designated directory but a stdout.log is found in tomcat/logs folder.
I am sure the init() method was fired because I have a quartz scheduler there. I am suspecting that my System.setProperty was not set. Any hint?
Update: With all the same source code, I have no problem if I am deploying with a WAR file. The ${LogPath} in log4j.properties work as expected.
Let me answer you the first question.
WAR file is a zip archive with different name. When you deploy this file to the Tomcat server, it unpacks this file to its folder as you would do it by copy-paste. If you are just developing your own project in your own environment and you don't want to distribute it, you don't need to create a war file. But if you want to distribute this project, I recommend you to create a war file. One file is easier to be sent.
Read more on Wikipedia http://en.wikipedia.org/wiki/WAR_%28file_format%29
Currently when I deploy a war file to Tomcat it can be downloaded from the URL via something like foo.com/myapp.war.
Most places recommend that you put an entry in a .htaccess file to prevent public access to any war files, or failing that an equivalent entry in your Apache config.
Unfortunately, my host does not provide access to the Apache config (although I can access Tomcat confs) and .htaccess files do not work for all Tomcat/Java related hosting environments. Pretty disappointing. They have been rather unhelpful in this respect.
Without resorting to something like "finding another host" (other than this issue they are fine - I'd rather stay here until my app grows too big), is there anything else I can do to prevent public users accessing my war files, yet still allow Tomcat to deploy the apps when it scans them?
For example, is it possible to specify one directory for Tomcat to scan for war files yet have it deploy the war into the public directories?
Thanks.
It is probably better to ask at https://serverfault.com/. It all boils down to how Tomcat is setup.
The vanilla setup will have a folder called webapps under CATALINE_HOME. You put your WAR archives there (they get auto-extracted and deployed). These folders will not be accessible from HTTP (you cannot download WAR archives from some URL like /webapps/my-test.war). These apps in webapps folder are deployed to some context roots. For example an application my-test.war will by default get deployed as yourhost.com/my-test/.
If you can download your WAR archives from foo.com/myapp.war maybe you can check out what does the CATALINA_HOME/webapp/ROOT app is doing. By default this is deployed under the foo.com. Ask from the host the Tomcat configuration files to figure what kind of custom configurations are they using.
You can place your .war files in any location Tomcat has access to. But you will have to tell Tomcat about it, so it picks them up. You can do this by placing a configuration XML file in
<CATALINA_HOME>/conf/Catalina/localhost/myWebapp.xml
There are samples on what to put into that file myWebapp.xml, e. g. here, step "4)". And of course, the official documentation.
I cannot find a proper way to add a directory to my app context on jboss 6.
I'll use this mapping for static content. Can someone give me a hand on that?
There are no more 'virtual directories' in JBoss 6. Apparently this went out with JBoss 5. The only available options I've found are:
create a blank /WEB-INF/web.xml (so like just <web-app/>) in your static content directory and make a symlink with a .war extension in your jboss deploy directory. You can also copy the directory containing the static content to your deploy directory, but I find a symlink much more useful.
create a webapp with a servlet that serves static content from a configured directory (discussed here)
if you're using a web framework like spring mvc 3, you can use the 'resources' feature to serve content for you (discussed here)
The bad news is that you can serve static content only inside JBoss applications. The good news is that it is very easy to transform any folder into an application folder.
The easiest solution is to copy all your static content into your server\default\deploy\ROOT.war directory.
A more complex solution is the following.
Copy the ROOT.war folder in the position where you want to put your
static content.
Rename ROOT.war into any name you like but it must end with .war,
for instance my_static_content.war.
Put all your static content into that directory.
Enable external deploy to the folder that contains your static
content folder. External deploy with JBoss 6 and JBoss 5
Restart JBoss
Your content will be into the URI http:\\localhost:8080\my_static_content\. You have to specify the exact name of the files that you want to serve, because directory listing is not allowed.
this thread helped me get static content in an external directory served up on jboss eap 5.1 without the use of links and without moving or renaming the ROOT.war folder.
note that you still have to create a directory structure that tricks jboss into serving up your content. it's not as easy as adding a <Context> child element to the <Host name="localhost"> in the server.xml file. it seems like a hack but at least it works.