在 Java EE 服务器中存储企业应用程序的状态(例如用于 lucene 索引)

发布于 2024-09-14 20:21:28 字数 109 浏览 6 评论 0原文

我需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

廻憶裏菂餘溫 2024-09-21 20:21:29

我不想自己决定文件系统中索引的位置。应用程序通常如何存储运行时创建的任何文件,引擎是否为每个应用程序提供任何类型的存储等

默认情况下,java.io包中的类根据当前的< em>工作目录 - 即文件系统中调用java命令的位置 - 您可以使用user.dir系统属性获取:

String curDir = System.getProperty("user.dir"); 

但这样做远非理想(实际上,写入文件对于便携式应用程序来说并不理想),我不推荐这种方法,但建议使用绝对文件系统路径和例如系统属性:

new File(System.getProperty("my.directory" + File.separator + "xxx");

其中属性 my.directory 将在应用服务器启动脚本中设置,例如假设 JBoss 安装在 /opt 下,使用 -Dmy.directory=/var/opt/jboss/ 符合 FHS 标准。

请记住:

  • 写入 FS 对于应用程序可移植性来说并不理想。如果可能,更喜欢写入数据库
  • 从 EJB 中使用 java.io 理论上是 禁止

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

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 the java command was invoked - that you can get using the user.dir system property:

String curDir = System.getProperty("user.dir"); 

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:

new File(System.getProperty("my.directory" + File.separator + "xxx");

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:

  • Writing to the FS is not ideal for application portability. Prefer writing to a database if possible
  • Using java.io from EJBs is in theory forbidden.
深居我梦 2024-09-21 20:21:29

通常,您在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.

一念一轮回 2024-09-21 20:21:29

我想说最好的方法是将数据存储在文件系统中的默认路径上,例如 /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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文