0

I've written a simple script that reads the contents of a locally stored folder and then lists the results using a JFileChooser.

This works perfectly fine from within the Eclipse compiler but when I export the project to a Jar file, it can no longer see the directory.

Folder structure: (the scripts are located in com.maths.game)

enter image description here

The script:

displayList = new JList<Object>(new File("res/Questions/").listFiles());
displayList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
displayList.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
displayList.setName("displayList");
displayList.setCellRenderer(new MyCellRenderer());
displayList.setSize((getWidth() / 2) + (getWidth() / 3) + (getWidth() / 30),(getHeight() / 3));
displayList.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.black));
displayList.setLocation((getWidth() / 15), (getHeight() / 3) + (getHeight() / 60));

And this is what is looks like from the Eclipse compiler.

enter image description here

The problem, from what I can tell, is the script can no longer see the 'Questions' folder and as a result, the script hangs. I'm struggling massively to see what the problem is. Any help would be greatly appreciated and if you need anymore information, I'll be happy to offer it up.

saljuama
  • 2,906
  • 1
  • 20
  • 42
connor.p
  • 866
  • 9
  • 19
  • 30
  • 2
    Not an answer, but wouldn't your program be much more flexible if the questions folder were not part of the jar file, but rather was a real OS-folder that hold files that could be more easily updated or improved? – Hovercraft Full Of Eels Jan 01 '16 at 19:20
  • 1
    have you verified the contents of the jar? to see if the directory and the files are actually there? and also, +1 to @HovercraftFullOfEels comment – saljuama Jan 01 '16 at 19:40
  • Hi, thanks for the input. I have checked the Jar file and the files are present and contain the correct data. I agree that having the files contained within the OS-folder makes more sense and is in fact another feature I have to include for a Save and Load function for the game I am creating but I am struggling with this also. – connor.p Jan 01 '16 at 19:42
  • @SalvadorJuanMartinez: there shouldn't be "Files" within a Jar file, just resources. – Hovercraft Full Of Eels Jan 01 '16 at 19:42
  • 2
    If your files are actually resources, and are placed in the jar, you can't access them using filesystem access methods. They are not on the filesystem - they are in the jar. – RealSkeptic Jan 01 '16 at 19:46
  • So how would I access them? and would I be able to write to them? – connor.p Jan 01 '16 at 19:47
  • @connor.p: again **you don't**. Again, to treat them as files, including using the file system, and especially to write to them, **make** them files, separate files that are not in the jar. This will easily solve your problems and this question. – Hovercraft Full Of Eels Jan 01 '16 at 20:03

0 Answers0