Search code examples
javafatal-errorauto-update

Problem with auto update, get fatal error while downloading config file for update4j


I am trying to write an application auto update with update4j. I wrote a basic app just to try how it works and how to do it, so I can use it in a real project. Think I did everything as documentation said, but it still doesn't work. I expected it to download config file from the given URL, but instead I get fatal error.

"[Fatal Error] :16:76: Attribute name "crossorigin" associated with an element type "link" must be followed by the ' = ' character."

The error is thrown when I try to read a Configuration file in the Updater class and line config = Configuration.read(in);

Can someone point me my mistake?

Here is everything that this app contains.

package Update;

import org.update4j.Configuration;
import org.update4j.FileMetadata;

import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ConfigCreator {
    private String appDir = System.getProperty("user.dir");
    private String theAppTarget = appDir + "\\TheApp\\target";
    private  String bootstrapTarget = appDir + "\\Bootstrap\\target";


    public void createConfig() throws IOException {
        Configuration config = Configuration.builder()
                .baseUri("https://github.com/Skurczybyk/UpdateTest/tree/master/TheApp/target")
                .basePath(theAppTarget)
                .file(FileMetadata.readFrom(theAppTarget + "\\TheApp-1.0-SNAPSHOT.jar"))
                .build();
        try (Writer out = Files.newBufferedWriter(Paths.get(bootstrapTarget + "\\config.xml")))
        {config.write(out);}
    }
}
package TheApp;


import Update.ConfigCreator;
import Update.Updater;

import java.io.IOException;
import java.net.MalformedURLException;

public class Main {
    public static void main(String[] args) {
        ConfigCreator confCreator = new ConfigCreator();
        Updater updater = new Updater();

        try {
            updater.update();
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
       /* try {
            confCreator.createConfig();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }*/


    }
}

package Update;

import org.update4j.Archive;
import org.update4j.Configuration;
import org.update4j.UpdateOptions;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Updater {
    public void update() throws MalformedURLException {

            URL configurl = new URL("https://github.com/Skurczybyk/UpdateTest/blob/master/Bootstrap/target/config.xml");
        Path updateZip = Paths.get("update.zip");
        Configuration config = null;
        try(Reader in = new InputStreamReader(configurl.openStream(), StandardCharsets.UTF_8))
        {
            config = Configuration.read(in);
        }
        catch (IOException e)
        {
            System.out.println("Cos nie poszło");
        }
    }
}


Solution

  • I found the answer to my question. Link to GitHub was not correct. When trying to reach a file from GitHub through code need to use raw version of URL. Didn't know of its existence before.