如何在 Linux debian 操作系统中的 tomcat Web 服务器上部署数据文件
我有一个使用 JSP 和 Servlet 开发的 Web 应用程序。该Web应用程序部署在操作系统为Debian Linux的服务器上,Tomcat版本为5.5.31。由于此应用程序需要一些数据文件,因此当使用独立的 java 应用程序完成设置时,将自动创建这些数据文件。该应用程序部署在另一台机器上。至此设置完毕。由于我对 Debian Linux 以及我的应用程序所在的位置了解不多,因此我对这些自动生成的数据文件的部署有一些疑问,如下所示
当我制作了我的 Web 应用程序的 .war 文件并部署它时使用 Tomcat 管理器。所以我不知道我的应用程序到底去哪里了。我不知道确切的路径。我如何找到它?
是否可以为部署在 Debian Linux 服务器上的 Web 应用程序创建 FTP?我认为,如果可以创建 FTP,那么我将使用我的独立 Java 程序直接连接到 FTP,并且可以轻松地创建文件以及其他文件和目录操作。
I have a web application developed using JSP and Servlet. This web application is deployed on server having Debian Linux as OS and The Tomcat version is 5.5.31. As this applications required some data files, These data files will be get created automatically when setting are done using a standalone java application. This application is deployed on another machine. This setup is done. As I dont know much about Debian Linux and where my application is goes on it so I have some doubts in deployment of these autimatically generated data files which are as follows
As I made the .war file of my web application and deployed it using Tomcat Manager. so I dont know where exactly my application goes. I dont know the exact path. How do I find it?
Is it possible to create FTP for this web application which is deployed on Debian Linux server? I think that if creating FTP is possible then I will directly connect to FTP using my Stand alone Java program and will easily do the creation of the file and other file and directory manipulation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您部署了战争,则该应用程序本身并不位于文件系统上的任何位置。大多数服务器都会在某个地方解开战争,但你不应该依赖那个地方。
我可以想到几个选项:
getServletContext().getAttribute("javax.servlet.context.tempdir") 获取应用程序的临时目录,然后通知您外部程序该位置并将文件放置在知道位置。
在应用程序之外安排一个“已知位置”,例如 /tmp/somewhere 或 /var/cache/your-app/somewhere 来放置此类文件。 (注意:/tmp 通常在 Linux 机器启动时清理)
至于从远程机器将文件上传到服务器:您可以让客户端将文件直接上传到您的 web 应用程序(例如 Apache HTTPClient 之类的东西会帮助您) ),这意味着您可以不用上面的“知道位置”。如果您想在应用程序之外执行此操作,我会避免使用 FTP(出于安全考虑)。相反,我会选择 scp(安全副本)。
编辑:稍微阅读一下字里行间,您在数据文件中提到了“设置”。如果这是一个在应用程序运行后就不会更改的配置文件,您可能会发现在服务器上执行“部署”步骤更方便,该步骤只需获取设置文件并将其添加到战争中,然后再部署它。以“蚂蚁大战”为例,这很容易。然后您可以使用 getClass().getResourceStream(..) 等访问该文件。
If you've deployed a war, the application isn't anywhere on the filesystem as such. Most servers will unpack the war somewhere, but you shouldn’t rely on where that is.
I can think of several options:
getServletContext().getAttribute("javax.servlet.context.tempdir") to get the application's temp directory, then inform you external program of this location and place the file somewhere in there in a know location.
Arrange for a "know location" outside of the application, such as /tmp/somewhere or /var/cache/your-app/somewhere to place such files. (Note: /tmp is usually cleaned on startup of a linux machine)
As for getting the file onto the server from a remote machine: You could get your client to upload the file directly to your webapp (something like Apache HTTPClient will help you there), which means that you could do without the "know location" above. If you want to do this outside of the application though, I'd avoid FTP (due to security). Instead, I'd go with scp (secure copy).
Edit: Reading between the lines a little, you mention "setting" in the data file. If this is a configuration file which is not changed once the app is running, you may find it more convenient to have a "deploy" step on your server which simply takes the settings file and adds it to the war before deploying it. This is easy enough with "ant war" for example. You could then access the file using getClass().getResourceStream(..) or such.