Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a jar from inside a jar?

Tags:

java

jar

I plan to execute a jar command using a jar that is included in another jar.

The command will automatically obfuscate a Java jar file using code similar to:

public void obfuscate()
{
    try
    {
        String jre = "\"" + System.getProperty("java.home") + "\\bin\\javaw.exe" + "\"";
        String jar = " -jar";
        Runtime.getRuntime().exec(new String[] { jre, jar.trim(), "/lib/allatori.jar /lib/config.xml" });
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

allatori.jar file is included in my main.jar file as a resource. config.xml file is also included.

How can I run my command so that it executes the included jar file?

Folder structure of main.jar:

- main.jar
  |
  |- main_class.class
  |- lib/
      |- allatori.jar
      |- config.xml
      |- jarToObfuscate.jar
like image 784
Manitoba Avatar asked Nov 05 '22 01:11

Manitoba


1 Answers

You will certainly have to unpack it outside the jar before running it.

like image 116
fmgp Avatar answered Nov 09 '22 09:11

fmgp