如何在 package.json 启动的同一命令行中 运行 节点服务器和 java 服务器

How to run node server and java server in same command line in package.json start

我需要 运行 :

node server.js

并且:

java -Xmx4g -cp 'libraries/corenlp/*' edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-french.properties -port 9000 -timeout 15000

我试过了:

node server.js; java -Xmx4g -cp 'libraries/corenlp/*' edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-french.properties -port 9000 -timeout 15000

或者

node server.js && java -Xmx4g -cp 'libraries/corenlp/*' edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-french.properties -port 9000 -timeout 15000

但在这两种情况下,当我在节点应用程序中询问时,java 服务器未 运行ning。但是如果我 运行 都在 2 个不同的控制台中指挥。 没有问题。 谢谢

编辑:我尝试在 npm start 中进行

您需要运行后台进程。请在命令末尾附加 & 以在后台 运行 它们。

node server.js &

java -Xmx4g -cp 'libraries/corenlp/*' edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-french.properties -port 9000 -timeout 15000 &

要杀死它们,您需要使用 ps -ef | grep 命令搜索这些进程。

好的,所以我找到了一种方法: 我的 package.json:

"scripts": {
    "start-nlp" : "java -Xmx4g -cp 'libraries/corenlp/*' edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-french.properties -port 9000 -timeout 15000 &",
    "start-node": "node server.js",
    "start": "npm run start-nlp && npm run start-node"

},