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.
Share
By default the classes in the
java.iopackage resolve relative pathnames against the current working directory – i.e. the location in the file system from where thejavacommand was invoked – that you can get using theuser.dirsystem 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.directorywould 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.iofrom EJBs is in theory forbidden.