-1

My little application works perfectly on Eclipse, instead give problems when I try to call its jar from command line. The problem looks like to reguard my resources folder where I put some properties file.

java.io.FileNotFoundException: file:*****************************\EasyDeployment\target\EasyDeployment-0.0.1-SNAPSHOT.jar!\ssh.properties
 (the syntax of the file name and the directory name or the value label it is not correct) // I translate this part that was in my native language
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at Configuration.PropertiesMenager.getAllKeys(PropertiesMenager.java:91)
        at GraphicInterface.SshChooser.initialize(SshChooser.java:101)
        at GraphicInterface.SshChooser.<init>(SshChooser.java:62)
        at GraphicInterface.SshChooser$1.run(SshChooser.java:49)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

my structure:

enter image description here

my references:

public final static String SSH_PROPERTIES = "ssh.properties";
    public final static String PORT_PROPERTIES = "port.properties" ;
    public final static String CMD_PROPERTIES = "cmd.properties" ;
    public final static String CONF_PROPERTIES = "configuration.properties";

example of a method that call these properties:

public String getPropertiyByKey(String key, String propFile) throws IOException {
        Properties prop = new Properties();
        FileInputStream objFileInputStream = null;
        objClassLoader = getClass().getClassLoader();
        String result = "";
        try {
            System.out.println(propFile);
            objFileInputStream = new FileInputStream(objClassLoader.getResource(propFile).getFile());
            prop.load(objFileInputStream);
            result=prop.getProperty(key);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            objFileInputStream.close();
        }   
        return result;
    }

1 Answers1

1

Always import files with getResourceAsStream() instead of getResource()

objFileInputStream = getClass().getClassLoader().getResourceAsStream(propFile)

You can find an explanation here