开发者

storing state of enterprise application in Java EE server (e.g for lucene index)

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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜