views:

43

answers:

3

Hi,
I need to create a Lucene index on a javaee 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.

Best Regards, Keshav

+2  A: 

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.

Mohsen
A: 

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

Alexander Kjäll
hi,what is the default path?
keshav.veerapaneni
Hi, The linux standard base says that that kind of information should go into /var if I remember correctly. That's why I suggested /var/lib/your_application/ as an example.
Alexander Kjäll
+1  A: 

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.
Pascal Thivent