Hello everyone!
I 'm working on a java application and in the program I use some files such as images, a local database and an .htm file (used as help file).
I have tried to make the access to these resources, location independent. So I've made in the package that contains my source files, a subfolder named resources and I've put there all these images,etc. I access them through .getResource() method, and not by using paths. For example that's how i access an image resource:
lang_icon=new javax.swing.ImageIcon(getClass().getResource("/myeditor/resources/checked.gif"));
The problem is that when the .jar file is built, it doesn't work properly. It loads the images successfully but cannot connect to the local database or open the .htm file.
Here is the code I use to access the .htm file (it works fine when I run the application through Netbeans)
URL helpFile= getClass().getResource("/myeditor/resources/help/help.htm");
try {
BrowserLauncher launcher = new BrowserLauncher();
launcher.openURLinBrowser(helpFile.toString());
} catch (BrowserLaunchingInitializingException ex) {
Logger.getLogger(mainAppFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedOperatingSystemException ex) {
Logger.getLogger(mainAppFrame.class.getName()).log(Level.SEVERE, null, ex);
}
and here is the code I use to access my local database
URL url = getClass().getResource("/myeditor/resources/icddb");
database = new File(url.getFile());
try
{
Class.forName("org.hsqldb.jdbcDriver");
con = DriverManager.getConnection("jdbc:hsqldb:file:" + database+"\\icddb", "sa", "");
When I try to open the .htm file through .jar file it shows this error "This file does not have a program associated with it for performing this action. Create an association in the Folder Options in control panel".
When I try to connect to my local database it says "Severe could not reopen database".
All ideas appreciated!
Thank you and sorry for my english!