Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my jar file launch on double click?

I'm having trouble launching a jar file on double click (and open with java SE ) ,the jar launches just fine from command line, other jars I have created launch fine from double click.

I exported the jar file using eclipse exporter ,I used the runnable jar export and and chose the right main() class under the run configuration

When I run the jar using java -jar myjar.jar it runs as expected no exceptions are thrown

I am under linux/windows both have the same problem I don't really see the point because other jar files I created using the same way run without any problem.

Just for fun I created a c program containing only

int main(void){
   system("java -jar myjar.jar");
   return 0;
}

When I double clicked the compiled c program my jar opened up !

Here is the MANIFEST

Manifest-Version: 1.0
Class-Path: . libs/commons-compress-1.10.jar libs/zip4j_1.3.2.jar libs/xz.jar libs/commons-io-2.4.jar libs/oat2dex.jar
Main-Class: deodex.Tester

Here is the main method : http://pastebin.com/M8Fhb4qW

package deodex;
import deodex.tools.Logger;
import deodex.ui.LangFrame;
import deodex.ui.Window;
public class Tester {
        public static void main(String args[]) {

        if (Cfg.isFirstLaunch()) {
                    Cfg.setCurrentLang(S.ENGLISH);
                    R.initResources();
                    @SuppressWarnings("unused")
                    LangFrame win = new LangFrame();


        } else {
            Cfg.readCfg();
            R.initResources();
            S.initTempFolders();
            Logger.logToStdIO("[test]" + Cfg.getCurrentLang());

                    @SuppressWarnings("unused")
                    Window win = new Window();



        }

    }
}

Thanks in advance

More details
I tried adding a new JFrame before my code and the double click works just for that JFrame that shows up and then it hangs there the other Windows that should launch just after that doesn't show up ,please tell me where to look ... why it does not work ? because it looks like my Classes that extends JFram needs terminal/cmd to show up ,I should also note that I am using a class called R to load the Strings from a text file depending on the Language and Cfg Class to check if the program first launched or has launched before and then load the proper language files and resources.

Edit
as suggested in the answer I removed all my JDK's and installed Oracle's JDk as described still have the same problem

like image 237
Rachid Boudjelida Avatar asked Nov 21 '22 15:11

Rachid Boudjelida


1 Answers

I solved My own problem here is why : as I said in the details I use text resources from outside the JAR file and I used hard code to get those resources like final File("lang/en.prop");the thing is when launching from the GUI with open with JAVA SE ,it is like running a command to my jar from an other directory which will fail because the Cfg class will throw a NullPointerException because the text resources are not there so I made a new Class called it PathUtils like this
PathUtils.java

    public static String getExcutionPath(){
        String path = "";
        try {
            path =PathUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("Somthing went wrong couldn't detemine our current location !");
        }
        return path.substring(0, path.lastIndexOf("/"));
    }

now at the Launch I will first find my location on the file system and then set the values of the needed files for my program based on my current locations and now double click works like a charm ! simple

like image 189
Rachid Boudjelida Avatar answered Nov 23 '22 07:11

Rachid Boudjelida