1

The following is my code, It works in windows with out error but when I setup my project in server (linux) it is not working and throws error

var spawn = require('child_process').spawn,
   javaCmd= spawn('java', ['-cp',__dirname+'/Java/jdk1.7.0_45/lib/dom4j.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/geronimo-stax-api_1.0_spec-1.0.1.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/gson-2.2.4.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/mysql-connector-java-5.1.6.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/ooxml-schemas-1.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/poi-3.9-20121203.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/poi-ooxml-3.9.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/xmlbeans-2.5.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/xmlbeans-xmlpublic-2.6.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/excelreader.jar',  'astral.excelreader.Main', catid, id,target_path]);


 javaCmd.stdout.on('data', function (data) {

        console.log(data);
  });
 javaCmd.stdout.on('close', function(code) {
    console.log(code);
  });
 javaCmd.stderr.on('data', function (data) {

        console.log(data);
  });

Following is the error

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

Anybody know its reason? I did n't set any other path for java. I tried to set using $ vi ~/.bash_profile but I got the following response

-bash: $: command not found

Anybody know how to set path in linux server

Parvathy
  • 2,275
  • 3
  • 24
  • 39
  • Try with this `spawn('/Java/jdk1.7.0_45/bin/java', [])` – damphat Jan 08 '14 at 12:18
  • Try putting a try catch block around the code that is failing so you can catch and output the error. That should give you more information to help figure out what the error actually is. – Brian Jan 08 '14 at 14:39
  • Also, if you do a quick search on stack overflow on "node.js spawn enoent" you will find most people having path issues, I would bet your problem will be the same. – Brian Jan 08 '14 at 14:41
  • @damphat not working, do you know how to set java path in linux – Parvathy Jan 09 '14 at 04:52
  • When you convert your app from Windows to Linux most probable bugs that will be encountered are related to the file system being case sensitive. – exebook Jan 24 '14 at 12:14
  • You can also catch process errors more elegantly with `javaCmd.on('error', function(e){console.error(e)});`. It will only provide the same information as the exception message but allows you handle it without it crashing your app. – ste2425 Aug 13 '14 at 14:15
  • Possible duplicate of [Fatal Error: Unable to find package java.lang in classpath or bootclasspath](http://stackoverflow.com/questions/28944890/fatal-error-unable-to-find-package-java-lang-in-classpath-or-bootclasspath) – Paul Sweatte May 17 '17 at 21:41

0 Answers0