0

i want to add an external jar to my application path , this is my code but it dosn't work.

code:

final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
        File Jar = null;
        try {
            Jar = new File(MyApp.class.getProtectionDomain().getCodeSource().getLocation().toURI());
        } catch (URISyntaxException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

          final ArrayList<String> command = new ArrayList<String>();
          command.add(javaBin);
          command.add("-classpath");
          command.add("\""+"C:\\path to file\\file.jar"+"\""+" ");
          command.add(Jar.getPath());
          Restart();
Garsov
  • 31
  • 6
  • You would be starting your application in a child process, while the current process presumably exits. Either way that's not the way to do it. Have a look at this answer: http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime – diginoise Apr 06 '17 at 08:44
  • Don't add the quotes. Commands are run directly, not through a shell, so quoting and spaces are not needed, just supply the parameters themselves. And of course, elements in the classpath are separated (in Windows) by `;`, not a space. – RealSkeptic Apr 06 '17 at 08:44
  • And please do follow the Java naming conventions. – Lew Bloch Apr 06 '17 at 08:56
  • @RealSkeptic can u explain , i want to build command :java -classPath file.jar App.exe – Garsov Apr 06 '17 at 13:21

0 Answers0