0

Hi I am getting a strange error when I am running my JavaFX application from a JAR. When I attempt to use a drop area in my app that I added, I get a strange error. This is what I get when run from CMD (java.lang.reflect.InvocationTargetException). On the GUI the drop operation just gets stuck and doesn't complete.

I know that the code works, because when I run it from my IDE it works fine.

Any help would be great.

public void onDragDrop(DragEvent event){
    files = new ArrayList<>();
    Dragboard db = event.getDragboard();
    boolean success = false;

    if(db.hasFiles()){
        //Do something with file.
        List<File> temp_files = db.getFiles();
        for(File f : temp_files){
            if(FilenameUtils.getExtension(f.getPath()).equals("ovpn")){
                files.add(f);
            }
        }
        lbl_dragger.setText("Files Dropped: " + files.size());
        success = true;
    }

    event.setDropCompleted(success);
    event.consume();
}

UPDATE: Upon further testing, it seems that the error is actually coming from the line below:

if(FilenameUtils.getExtension(f.getPath()).equals("ovpn")){
    files.add(f);
}

There seems to be some kind of error with the library I was using (ApacheCommons). As a workaround (unless this question gets an answer) using a simple (but less accurate) method will be suitable. See below if you too are stuck on this:

if(f.getAbsolutePath().contains(".ovpn")){
    files.add(f);
}
James McNee
  • 302
  • 2
  • 14
  • Could you post the full stacktrace + error message? – fabian Nov 20 '16 at 10:03
  • Hi, seeing as this only occurs when running from the jar, I can only post what I get from CMD. That is all that I get. I'm stumped. – James McNee Nov 20 '16 at 10:04
  • I have updated my question with some new information. – James McNee Nov 20 '16 at 10:11
  • Do you have a `catch` block somewhere in your code that just prints out the exception? If so, try adding `e.printStackTrace();` to that `catch` block. – Luke Woodward Nov 20 '16 at 10:40
  • The exception is not thrown from my code. It's thrown and caught in the ApacheCommons library (I'm assuming), so I have no way to get any more info than what was thrown by CMD. – James McNee Nov 20 '16 at 10:43
  • Having checked [the source code of the FilenameUtils class](https://commons.apache.org/proper/commons-io/javadocs/api-2.5/src-html/org/apache/commons/io/FilenameUtils.html), I don't believe there's any way the Apache Commons library could throw that exception. Given that your code works in the IDE but not in the JAR my best guess is that the Apache Commons library isn't on the classpath when the JAR runs. See, for example, [this question](http://stackoverflow.com/questions/18413014/). – Luke Woodward Nov 20 '16 at 11:35
  • Hmm, I am sure that I included the library correctly. I have done this in other projects too. Even if this was the case I doubt it would throw that exception, and not one of the others that are shown on the link you posted. – James McNee Nov 20 '16 at 11:41

0 Answers0