I have a java application which I will be distributing to Mac and Windows OS systems. The app uses hibernate to communicate with an SQL Lite database to read and write data. I have been able to generate the .jar file and used Lauchj4 to create the .exe. Since I have found out that .jars are not changeable I have included the database inside the .jar and when the application first runs it will make a copy of the database in its root folder. This is the database which the app will be communicating with.
So far that has worked fine. However when It comes to installing the app in the windows /Program Files folder I run into an issue when the app runs. When it comes to reading from the database all is good. The issue happens when I need to write to the database. An exception occurs. I believe this is because of the permissions in the program files folder because if I move that app to another folder all is well.
Is there a way to workaround this problem? I don't feel comfortable changing permissions in the program files folder. I am considering copying the database into a the user's \Application Data
folder. However my hibernate configs are specified in an xml file as shown:
<!-- SQLite -->
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<beans:property name="driverClassName" value="org.sqlite.JDBC" />
<beans:property name="url"
value="jdbc:sqlite:database.db" />
</beans:bean>
So how can I point this bean's url property to the user's \Application Data
folder at runtime?
Another thing I need to consider is... how can create a solution that will be suitable for Windows and Mac?