简体   繁体   English

Java WebApp-将应用程序生成的文件放在哪里?

[英]Java webapp - where to put application-generated files?

I'm working on a Java web application that needs to store uploaded files in one directory, and an embedded Neo4j database in another directory. 我正在开发一个Java Web应用程序,该应用程序需要将上载的文件存储在一个目录中,而将嵌入式Neo4j数据库存储在另一个目录中。 I'm deploying the warfile to Tomcat to serve the application, and the application needs to be runnable under Tomcat in either Linux or Windows. 我正在将warfile部署到Tomcat,以为应用程序提供服务,并且该应用程序需要在Linux或Windows的Tomcat下可运行。

Where exactly should I be putting these two directories on the host system's filesystem? 我应该将这两个目录放在主机系统的文件系统上的确切位置?

I'm confused since I'm accustomed to storing information in databases specified via a URL, etc. Thanks for the help. 我很困惑,因为我习惯于将信息存储在通过URL等指定的数据库中。感谢您的帮助。

Is there a chance webapp have two or more instances running at the same time, say in a same Tomcat with two /path names? webapp是否有可能同时运行两个或多个实例,例如在具有两个/ path名称的同一个Tomcat中运行?

Java has system property user.home you could always create a subfolder on it. Java具有系统属性user.home,您始终可以在其上创建一个子文件夹。 Current user is the one running Tomcat server. 当前用户是正在运行的Tomcat服务器。 Print properties to sysout for debug purpose. 将属性打印到sysout中以进行调试。

Reading a webapp name at runtime you can use servletContext.getRealPath("/") function. 在运行时读取Web应用程序名称,可以使用ServletContext.getRealPath(“ /”)函数。 You get a filename path to $tomcat/webapps/mywebapp and use last folder entry. 您将获得$ tomcat / webapps / mywebapp的文件名路径,并使用最后一个文件夹条目。 Define ServletContextListener in web.xml so you can read webapp name at startup. 在web.xml中定义ServletContextListener,以便您可以在启动时读取webapp的名称。

Use naming convention ${user.home}/tomcat/${webappname}/ and store any file you please. 使用命名约定$ {user.home} / tomcat / $ {webappname} /并存储您喜欢的任何文件。

Or define a webapp context-param variable in web.xml file and let deployer create an appropriate folder. 或在web.xml文件中定义一个webapp context-param变量,然后让部署者创建一个适当的文件夹。

http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html
http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getInitParameter%28java.lang.String%29 http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getInitParameter%28java.lang.String%29

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM