Skip to content

Commit

Permalink
Using requireMain to start RhinoVerticle
Browse files Browse the repository at this point in the history
  • Loading branch information
nelson.silva committed May 11, 2012
1 parent d494479 commit e619703
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/examples/javascript/commonjs/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Server, handler;

Server = require('server');
handler = require('handler');
Server = require('./server');
handler = require('./handler');

server = new Server(8080, 'localhost');
server.use(handler);
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/org/vertx/java/deploy/impl/rhino/RhinoVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,14 @@ public static Require installRequire(Context cx, ScriptableObject scope, List<St
return require;
}

private static void installRequire(ClassLoader cl, Context cx, ScriptableObject scope){
private static Require installRequire(ClassLoader cl, Context cx, ScriptableObject scope){
List<String> modulePaths= new ArrayList<>();

// Get the URLs
// Must add current path since Rhino can't resolve relative module IDs when require() is used outside of a module
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url : urls){
modulePaths.add(url.getPath());
}
// Hack to add the javascript core library to the module path
String corePath = new File(cl.getResource("vertx.js").getPath()).getParent();
modulePaths.add(corePath);

installRequire(cx, scope, modulePaths, false);
return installRequire(cx, scope, modulePaths, false);
}

private static void loadScript(ClassLoader cl, Context cx, ScriptableObject scope, String scriptName) throws Exception {
Expand Down Expand Up @@ -150,8 +144,8 @@ public void start() throws Exception {
scopeThreadLocal.set(scope);
clThreadLocal.set(cl);

installRequire(cl, cx, scope);
loadScript(cl, cx, scope, scriptName);
Require require = installRequire(cl, cx, scope);
require.requireMain(cx, scriptName);

try {
stopFunction = (Function)scope.get("vertxStop", scope);
Expand Down

0 comments on commit e619703

Please sign in to comment.