Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoppioJVM from NPM doesn't work in browser #390

Closed
sreym opened this issue Nov 30, 2015 · 3 comments
Closed

DoppioJVM from NPM doesn't work in browser #390

sreym opened this issue Nov 30, 2015 · 3 comments

Comments

@sreym
Copy link

sreym commented Nov 30, 2015

I tried to install Doppio via NPM and it doesn't work...

I'll try to describe what I did.

I created a new project and typed next commands:

$ npm install doppiojvm
$ npm install browserfs

Then I added in the root a simple html file:

<html>
<head>
<script type="text/javascript" src="node_modules/browserfs/dist/browserfs.js"></script>
<script type="text/javascript" src="node_modules/doppiojvm/dist/dev/doppio.js"></script>
</head>
<body>

<script type="text/javascript">
  (function() {
      var mfs = new BrowserFS.FileSystem.MountableFileSystem(),
          fs = BrowserFS.BFSRequire('fs');
      BrowserFS.initialize(mfs);

      mfs.mount('/tmp', new BrowserFS.FileSystem.InMemory());
      mfs.mount('/home', new BrowserFS.FileSystem.LocalStorage());
      mfs.mount('/sys', new BrowserFS.FileSystem.XmlHttpRequest(
        'listings.json',
        'node_modules/doppiojvm/dist/dev')
      );

      new Doppio.VM.JVM({
        bootstrapClasspath: ['/sys/vendor/java_home/classes'],
        classpath: [],
        javaHomePath: '/sys/vendor/java_home',
        extractionPath: '/tmp',
        nativeClasspath: ['/sys/src/natives'],
        assertionsEnabled: false,
        tmpDir: '/tmp'
      }, function(err, jvmObject) {
        if (err) {
          console.error(err);
        }
      });
    })();
</script>

</body>
</html>

When I try to run it in a browser (via http-server) there is an error in console: Failed to initialize Ljava/lang/reflect/Constructor;.

I tried to diagnose this but it's too complicated for quick fix. I'm not sure that I created correct HTML-file for this test case. I've found that loading of superclass of Constructor is failed (Executor).

@sreym sreym changed the title DoppioJVM doesn't work in browser DoppioJVM from NPM doesn't work in browser Nov 30, 2015
@jvilk
Copy link
Member

jvilk commented Nov 30, 2015

Change /sys/src/natives to /sys/natives. I moved the folder before the NPM release to make the directory structure clearer.

I'd like to apologize for how difficult it is to get DoppioJVM up and running. The next release will be much easier to use, and will have proper documentation.

Thanks, btw, for your wiki edits. However, I actually didn't know the wiki was publicly editable, so I changed the permissions so other people cannot edit it.

Some of your information was slightly incorrect -- in the callback passed to the constructor, you should not call arbitrary Java methods. Instead, you should call a class with a Main function, as you would with a regular JVM. That Main function can then invoke a native method, which can then begin invoking arbitrary JVM methods.

If you run hello()Ljava/lang/String;, the JVM will immediately shut down once hello() finishes running!

The next version of DoppioJVM will have a much clearer API, and will have more sanity checks.

@jvilk jvilk closed this as completed Nov 30, 2015
@hrj
Copy link
Contributor

hrj commented Dec 9, 2015

Change /sys/src/natives to /sys/natives.

Perhaps you can edit the wiki to reflect this. It tripped me a couple of times. Thanks!

@jvilk
Copy link
Member

jvilk commented Dec 9, 2015

Sure; done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants