ReadyTalk / avian

[INACTIVE] Avian is a lightweight virtual machine and class library designed to provide a useful subset of Java's features, suitable for building self-contained applications.
https://readytalk.github.io/avian/
Other
1.22k stars 172 forks source link

Best way to use Avian for automated builds #490

Closed mainrs closed 8 years ago

mainrs commented 8 years ago

What is the best way to use avian for automated builds based on maven? Maven will create a jar file containing the logic of the application. But how exactly should I embed the app into avian? Downloading it via git, setting it then up in a folder in the build directory and then running some custom script to embed it like in the example? How do you guys do it yourself? It should be 100% automated without the need to copy files from x to y.

joshuawarner32 commented 8 years ago

Once upon a time, we always rebuilt everything from source, from adjacent repositories, using pretty much exactly the process described in the readme. Since then, we've transitioned to using a variety of pre-built binaries (libavian.a and binaryToObject) for various host and target platform/arch combos, stored in our private artifact repository, and downloaded as a gradle dependency. We then use a hacked-together combo of makefile and gradle script to compile a custom entrypoint (again, as the readme describes), and call out to the native linker tools to build the final binary. It's in no state to release publicly and even if it was, I'm not sure it would help anyone since what you need to include in any given binary and how you need it compiled/linked can vary widely between projects.

At one point, there was an effort to clean that up and open-source it as a gradle plugin to automate at least the simple scenarios. However, that's since fizzled out because the projects we use avian for internally have gone into maintenance-only mode, and the person who was driving that effort left the company.

Long story short: I agree that the process is not exactly straight-forward, but it is perfectly automatable. I comes down to running all those same commands from your favorite scripting language or build system, optionally caching the output at one or more stages for efficiency. It's unlikely to improve, except perhaps through the enterprising efforts of external contributors.

If you have specific questions, I'd be happy to answer them.

mainrs commented 8 years ago

Mind if I ask something else here? I wrote a simple program that just needs to open a URL connection and download the file to the computer. The problem is that it only reads the first 178 bytes from a file that is over 20 MB big and then the program hangs without any reason. I compiled it against boot.jar to be sure. Running the program in an IDE works perfectly. I do not know where the problem is. Here is the source code if it is of any help:

import java.io.*;
import java.net.URL;

/**
 * Created by Sven on 27/06/16.
 */
public class Launcher2 {

    public static void main(String[] args) throws Exception {
        final URL url = new URL("https://sirwindfield.github.io/taskflow/application-support/test.jar");

        new Thread() {
            @Override
            public void run() {
                System.out.println("started");
                // download the file and update the value
                byte[] buffer = new byte[4096];
                int bytesRead = 0;
                File output = new File("test.zip");
                try {
                    output.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                InputStream is = null;
                OutputStream out = null;

                try {
                    is = url.openStream();
                    out = new BufferedOutputStream(new FileOutputStream(output));

                    while ((bytesRead = is.read(buffer)) != -1) {
                        out.write(buffer, 0, bytesRead);

                        // update progress bar
                        final int change = bytesRead;
                        System.out.println("read " + bytesRead + " in last ieration");
                        System.out.flush();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (is != null)
                            is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        if (out != null)
                            out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("stopped");
            }
        }.start();
    }
}
lwahlmeier commented 8 years ago

If your using the Avian classpath you would need to do this with http instead of https. The Avian classpath does not currently support ssl type connections. If you are using openJDK or android classpath then let me know, but it should work with those.

mainrs commented 8 years ago

Tried it with openjdk, it doesn't let me compile. I downloaded it from here: https://github.com/alexkasko/openjdk-unofficial-builds Couldn't find any other download path. The build complains about files missing in the openjdk src folder. There is no native folder.

lwahlmeier commented 8 years ago

So getting a openjdk build of avian working is no small feat. I dont think the avian dynamic build stuff works anymore, so you have to have the openjdk native source code, not just the openjdk classpath.

I did test your example code, with the avian classpath I had the same issue, using avian with openjdk does fix it.

mainrs commented 8 years ago

Do you have an openjdk lying around? I can't find any native code for openjdk online.

lwahlmeier commented 8 years ago

openjdk's source is in mercurial so you can do: hg clone http://hg.openjdk.java.net/jdk7/jdk7

hg clone http://hg.openjdk.java.net/jdk8/jdk8

once you clone you have to run the get_source.sh in the repo to download the source code from the sub projects. Compiling openjdk can be kind of a pain, but once you do you can build avian with the openjdk and openjdk_src paths.

the build would look like this: make openjdk=/path/to/jdk7/install openjdk_src=/path/to/repo/jdk7/jdk/src

If you have an already build jdk7 you might be able to get away with using that and the source path, just try to keep them the same version or there might be native library problems.