Note that there are some explanatory texts on larger screens.

plurals
  1. POJAR launches fine when run through Terminal, but not when double-clicked
    primarykey
    data
    text
    <p>So I'm trying to load a file using a jar. The file is <strong>outside</strong> of the jar, but in the same folder. When I run the jar form the terminal using java -jar Test.jar it works just fine, but if I run it by double clicking the jar it does not <em>correctly</em> load from the file. I can load external Images just fine with either method, but not a file I have created. This is running on Mac OSX. This problem also seems to exist on Ubuntu. On Windows, however, the File is loaded even more incorrectly.</p> <p>The Path loaded from seems to be the same for both cases. When running from terminal, the output for numbers is correct. However, when running by double clicking, any number over 127 is loaded improperly. I have researched for hours for a solution, with no avail.</p> <p>EDIT: This is my manifest</p> <pre><code>Main-Class: Test </code></pre> <p>I have created this simple application to demonstrate my problem.</p> <p>This is what writes the file that will be read.</p> <pre><code>import java.io.*; public class TestWriter{ public static void main(String[] args){ try{ // Create the file and FileWriter. FileWriter out = new FileWriter(new File("test.map")); // Write some test numbers. for (int i = 0; i &lt; 481; i += 30) out.write(i); // Flush the output (for good measure?) out.flush(); // Close the output. out.close(); } catch (IOException e){ e.printStackTrace(); } } } </code></pre> <p>This is what loads the file.</p> <pre><code>import javax.swing.JComponent; import java.awt.*; import java.net.*; import java.io.*; import javax.imageio.*; import java.awt.image.*; public class Run extends JComponent{ // Image to be drawn on screen BufferedImage IMAGE; // Output to be drawn on screen String string = ""; // Loading a MAP file - includes loading a bmp image and a .map (txt file). public Run(){ // MAP name String map = "test"; System.out.println("Loading map: "+map); // Get path String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); String decodedPath = ""; // Decode path try{ decodedPath = URLDecoder.decode(path, "UTF-8"); decodedPath = decodedPath.substring(0, decodedPath.lastIndexOf("/") + 1); } catch (Exception e){ System.out.println("Could not decode path."); e.printStackTrace(); System.exit(1); } // Add decoded path to output string string += decodedPath; try{ IMAGE = ImageIO.read(new File(decodedPath+"/"+map+".bmp")); System.out.println("MAP image loaded."); } catch (IOException e){ System.out.println("Could not load MAP image."); e.printStackTrace(); System.exit(1); } try{ System.out.println("Loading MAP data."); // Create a new reader FileReader in = new FileReader(new File(decodedPath+"/"+map+".map")); // While there is something left to be read while (in.ready()){ // add the next input to the output string string += ", "+in.read(); } // Close the input (for good measure) in.close(); System.out.println("Loaded MAP data."); } catch (Exception e){ System.err.println("Could not load MAP data."); e.printStackTrace(); System.exit(1); } // Repaint the screen to show our newly loaded image and string repaint(); } public void paint(Graphics g){ g.drawImage(IMAGE,0,0,null); g.drawString(string,16,64); } } </code></pre> <p>This is the main method that creates the JFrame and adds the component Run()</p> <pre><code>import javax.swing.JFrame; import javax.swing.JComponent; public class Test{ public static void main(String[] args){ System.out.println("\nInitializing..."); JFrame frame = new JFrame("Test"); int frameWidth = 640; int frameHeight = 200; frame.setSize(frameWidth,frameHeight); frame.setResizable(false); frame.setLocation(240,60); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new Run()); frame.setVisible(true); System.out.println("Running..."); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload