Bacon2305
Bacon2305

Reputation: 311

JAVA HOME PATH correctly set in Environment but wrong when compiling via Node.js

I received this isue: com.sun.tools.javac.Main is not on the classpath. Oerhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\Program Files\Java\jre7"

However, my JAVA HOME is set as follows:

C:\Program Files\Java\jdk1.7.0_51

With PATH

C:\Program Files\Java\jdk1.7.0_51

Any recommendations?

Upvotes: 0

Views: 2567

Answers (2)

Manish
Manish

Reputation: 13577

Just uninstall node js and re install node js. Its solve my problem.

Upvotes: 1

JBCP
JBCP

Reputation: 13485

When node.js spawns a forked environment, it doesn't copy over your user's environment variables. You will need to do that manually.

You will need to get JAVA_HOME from process.env and set it in your exec() call. Something like this should work:

var config = {
    env: process.env
};
exec('javacmd', config,
    function() {
        console.log(arguments);
});

Or if you wanted to be more explicit, you could extract only the variables you needed (JAVA_HOME, etc) from process.env

See here for more details:

How to exec in NodeJS using the user's environment?

Upvotes: 1

Related Questions