Running Node.js applications on the JVM with Nashorn and Java 8
The following steps show how to run a simple Node.js web application on OSX. The steps should be very similar for Linux or Windows.
Download
avatar-js.jar
from the java.net Maven Repo. Current version is here: https://maven.java.net/content/repositories/public/com/oracle/avatar-js/0.10.25-SNAPSHOT/ Example file: avatar-js-0.10.25-20140313.063039-43.jar
Download the native library
avatar-js.dylib
from the java.net Maven Repo. Current version is here: https://maven.java.net/content/repositories/public/com/oracle/libavatar-js-macosx-x64/0.10.25-SNAPSHOT/ Example file: libavatar-js-macosx-x64-0.10.25-20140312.062209-35.dylib For Linux you would download the corresponding .so
file from ../libavatar-js-linux-x64/0.10.25-SNAPSHOT/
For Windows you would download the corresponding
.dll
file from ../libavatar-js-win-x64/0.10.25-SNAPSHOT/
Rename the native library to
avatar-js.dylib
and rename the jar to avatar-js.jar
and put both in a directory called dist
123456789101112131415</em>
var
http = require(
'http'
);
// Configure our HTTP server to respond with Hello World to all requests.
var
server = http.createServer(
function
(request, response) {
response.writeHead(200, {
"Content-Type"
:
"text/plain"
});
response.end(
"Hello World\n"
);
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
<em>
Run the command:java -Djava.library.path=dist -jar dist/avatar-js.jar app.js
The output should be:
Server running at http://127.0.0.1:8000/
Comments
Post a Comment