在 Java EE 服务器中存储企业应用程序的状态(例如用于 lucene 索引)
我需要在 Java EE 应用程序启动时创建 Lucene 索引,但我不想自己决定索引在文件系统中的位置。应用程序通常如何存储运行时创建的任何文件,引擎是否为每个应用程序提供了任何类型的存储,我可以使用。
I need to create a Lucene index on a Java EE application startup, but I do not want to decide on the location of the index in filesystem myself. How do applications in general store any files created while running, is there any kind of store provided by the engine per application basis etc. that I can use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,
java.io
包中的类根据当前的< em>工作目录 - 即文件系统中调用java
命令的位置 - 您可以使用user.dir
系统属性获取:但这样做远非理想(实际上,写入文件对于便携式应用程序来说并不理想),我不推荐这种方法,但建议使用绝对文件系统路径和例如系统属性:
其中属性
my.directory 将在应用服务器启动脚本中设置,例如假设 JBoss 安装在
/opt
下,使用-Dmy.directory=/var/opt/jboss/
符合 FHS 标准。请记住:
java.io
理论上是 禁止。By default the classes in the
java.io
package resolve relative pathnames against the current working directory - i.e. the location in the file system from where thejava
command was invoked - that you can get using theuser.dir
system property:But doing this is far from ideal (actually, writing to files is not ideal for portable applications) and I don't recommend this approach but suggest using absolutes filesystem paths and e.g. system properties:
Where the property
my.directory
would be set in the app server startup script e.g. assuming JBoss is installed under/opt
, using-Dmy.directory=/var/opt/jboss/<somedir>
to be FHS compliant.Just keep in mind that:
java.io
from EJBs is in theory forbidden.通常,您在JBoss和Tomcat等应用服务器中的当前目录(.)中创建Lucene索引,index文件夹创建在bin文件夹中,这根本不是一个好主意。
您可以使用 Compass 将索引文件存储在数据库(或几乎任何其他存储设备)中,或者存储它位于文件系统上的路径中。
据我所知,Java EE 容器中没有特殊的每个应用程序存储。
Normally you create a Lucene index in application servers like JBoss and Tomcat in the current directory (.), index folder is created in bin folder, which is not a good idea at all.
You can either store your index files in database (or virtually any other storing device) using Compass or store it in a path on the file system.
There is no special per-application storage as far as I know in Java EE containers.
我想说最好的方法是将数据存储在文件系统中的默认路径上,例如 /var/lib/your_application/ ,然后使该位置可配置。
您可以在这里阅读更多信息:
http://www.pathname.com/fhs/ pub/fhs-2.3.html
I would say that the best way is to store the data on a default path in the filesystem, for example /var/lib/your_application/ and then make that location be configurable.
You can read more here:
http://www.pathname.com/fhs/pub/fhs-2.3.html