简体   繁体   English

在Java Project中存储XML文件

[英]Storing XML Files in Java Project

Apologies for the fairly open question however I feel it needs to be this way. 对于这个相当开放的问题,我们深表歉意。

In any given Java project, preferably a web service, have you ever had to store XML files? 在任何给定的Java项目(最好是Web服务)中,您是否曾经存储过XML文件? At the moment I am creating a Google Web Toolkit web service and I need a way to 'store sessions'( like in iGoogle to store the layout ). 目前,我正在创建Google Web Toolkit网络服务,并且需要一种“存储会话”的方式(例如在iGoogle中存储布局)。 However once I have this mechanism down... I need a place to store the files on the server. 但是,一旦我关闭了该机制,就需要在服务器上存储文件的位置。

I've thought about storing them in the 'Resources' folder in the Java project ( src/main/resources/ ) however something tells me this is impossible as it's deployed to a Tomcat server packaged up in a .war . 我曾考虑过将它们存储在Java项目( src/main/resources/ )的“ Resources”文件夹中,但是有消息告诉我这是不可能的,因为它已部署到打包在.war的Tomcat服务器中。

Is there any standard way of handling this? 有什么标准的方法可以处理吗? Does anyone have any ideas on a way in which I should approach it? 有人对我应该采取的方式有任何想法吗? In a Python project I have done, I whacked config files straight into /path/to/resources/folder however I feel it doesn't need to be this complicated?! 在我完成的Python项目中,我将配置文件直接插入/path/to/resources/folder但是我觉得它不需要这么复杂吗?

  • you can designate a configurable external directory for such files. 您可以为此类文件指定可配置的外部目录。
  • some database systems have XML fields, so you can also store it there 一些数据库系统具有XML字段,因此您也可以将其存储在此处
  • you can store it as CLOB in the DB 您可以将其作为CLOB存储在数据库中

No this shouldnt need to be complicated, but it is because it depends on whether the server you deploy to allows you access to the file system. 不需要,这不必太复杂,这是因为这取决于您部署到的服务器是否允许您访问文件系统。 If it does, then its easy - just create a data directory, and save the files there. 如果是这样,那么就很容易-只需创建一个数据目录,然后将文件保存在那里。

Otherwise, you can save them as blobs in a database, or whereever your persistence layer is. 否则,您可以将它们另存为blob到数据库中,或者保存在持久层中的任何位置。 you face the same problem in python - if you whack the file into /path/to/resources/folder, and you dont have write permission - then your app fails. 您在python中会遇到相同的问题-如果将文件重击到/ path / to / resources / folder,并且没有写权限,则您的应用程序将失败。 this problem is not generic to java. 这个问题不是java通用的。

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

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