I have created project that should display file "pattern.xml" which is located in /src/files/pattern.xml
.
It works fine when I run code in eclipse. But when I export project to executable jar and try to execute it, jar doesn't work.
Maybe problem is here?
URL dir_url = this.getClass().getClassLoader()
.getResource("files\\pattern.xml");
Here is code. Any ideas?
public class ResourseClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
test t = new test();
t.Go();
}
}
class test {
void Go() {
try {
URL dir_url = this.getClass().getClassLoader()
.getResource("files\\pattern.xml");
File dir = new File(dir_url.toURI());
if (dir.exists()) {
System.out.println("file exists");
}
FileReader frI = new FileReader(dir);
BufferedReader br = new BufferedReader(frI);
String text;
String textout = "";
while ((text = br.readLine()) != null) {
textout = textout + text + "\n";
}
JOptionPane.showMessageDialog(null, textout, "Information",
JOptionPane.WARNING_MESSAGE);
br.close();
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (URISyntaxException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
}
}
Package window
Normal execution in eclipse
When code is executed in eclipse it works.