2
votes

I'm am very confused with this problem. It didn't happen for the first few times when ran this code, but after that, I couldn't get it running again. It only breaks after downloading it using my Java code. The code I have downloads a jar file from my website and then uses ProcessBuilder to run it. It all worked fine the first couple of times, but I ran it a few more times and it started giving me

no main manifest attribute, in ...\AppData\Local\GDRQ\bin\launch_gdbotbin.jar

Here is the java code I use to download and run the jar file:

try {
        System.out.println("starting update...");

        File targetFile = new File(System.getProperty("user.home") + "\\AppData\\Local\\GDRQ\\downloading\\launch_gdbotbin.jar");
        URL downloadUrl = new URL("http://www.dropmoose.com/gdbotpro/launch_gdbotbin.jar");

        InputStream inStream = downloadUrl.openStream();
        //System.out.println(inStream.available());
        BufferedInputStream bufIn = new BufferedInputStream(inStream);
        OutputStream out = new FileOutputStream(targetFile);
        BufferedOutputStream bufOut = new BufferedOutputStream(out);
        byte[] buffer = new byte[inStream.available()];

        while (true) {
            int nRead = bufIn.read(buffer, 0, buffer.length);

            if (nRead <= 0) {
                break;
            }

            bufOut.write(buffer, 0, nRead);
        }

        bufOut.flush();
        out.close();
        inStream.close();

        BufferedWriter bw = new BufferedWriter(new FileWriter(settingsFile));
        for (int i = 0; i < settings.size(); i++) {
            bw.write(settings.get(i));
            bw.newLine();
        }

        bw.close();
        System.out.println("update successful");
        infoPane.dispose();

        System.out.println("cleaning up...");
        Files.move(targetFile.getAbsoluteFile().toPath(), new File(System.getProperty("user.home") + "\\AppData\\Local\\GDRQ\\bin\\launch_gdbotbin.jar").toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (Exception e) {
        JOptionPane.showConfirmDialog(null, "An error occured (code 14): Unable to update!");
        infoPane.dispose();
    }

String[] parm = {"jar", "-jar", System.getProperty("user.home") + "\\AppData\\Local\\GDRQ\\bin\\launch_gdbotbin.jar"};

ProcessBuilder pb = new ProcessBuilder(parm);
    pb.redirectOutput(Redirect.INHERIT);
    pb.redirectError(Redirect.INHERIT);

    try {
        pb.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

I tried creating a MANIFEST.MF file with Class-Path as the class with the main(String[] args) method and Manifest-Version: 1.0 but it still didn't work. What am I doing wrong and why is my manifest.mf file not working? The jar that the code downloads is also about 125KB when the original one is 2.5 MB.

EDIT If you go to the url in the code that downloads the jar file and then run it, it runs perfectly fine.

EDIT 2 I even tried going into the downloaded jar file using WinRAR and manually changing the META-INF/MANIFEST.MF file to have the Main-Class set properly, and after doing so, it still didn't run.

EDIT 3 The manifest problem is gone. But now I have a problem with loading referenced libraries. I am using PircBotX and when you run the jar file (using String[] parm = {"java", "launch_gdbotbin.jar", "gd.bot.main.BotHandler"}) it throws ClassNotFoundException.

EDIT 4 Even after I did what Micheal Markidis recommended, it started giving me the no main manifeset attribute error again.

1
What does the parm String look like?Michael Markidis
String[] parm = {"jar", "-jar", System.getProperty("user.home") + "\\AppData\\Local\\GDRQ\\bin\\launch_gdbotbin.jar"};TreeHouseFalcon
Aren't you trying to run the jar file from java? Wouldn't you use the java command instead?Michael Markidis
If I use "java -jar path/to/jar/file", it does the same thing.TreeHouseFalcon

1 Answers

0
votes

I can actually get your code to run:

What I changed for my environment:

  1. I took out the code that writes the settings file
  2. I took out the code that does the move

    Files.move(targetFile.getAbsoluteFile().toPath(), new File(System.getProperty("user.home") + "\AppData\Local\GDRQ\bin\launch_gdbotbin.jar").toPath(), StandardCopyOption.REPLACE_EXISTING);

  3. You need to have the

    String[] parm = {"java", "-jar", System.getProperty("user.home") + "path/to/your/file/launch_gdbotbin.jar"};

I get this to come up enter image description here

  1. I would try to replicate what I did and then incrementally put back the other pices of code that I removed.

Note: Just manually delete the launch_gdbotbin.jar each time for now.