简体   繁体   English

使用 NodeJS 提取.jar 文件

[英]Extract .jar file with NodeJS

I need to extract a JAR file using NodeJS and I have no idea how, also I'm not sure if StackOverFlow is the right place for this so sorry if it's not.我需要使用 NodeJS 提取 JAR 文件,但我不知道如何,我也不确定 StackOverFlow 是否适合这个地方,如果不是,很抱歉。

so jar files are just java archive files that can be unzipped with any commonly available operating system tool like unzip or jar , so a simple command like jar xvf /path/to/file.jar or unzip /path/to/file.jar should extract any.jar file. so jar files are just java archive files that can be unzipped with any commonly available operating system tool like unzip or jar , so a simple command like jar xvf /path/to/file.jar or unzip /path/to/file.jar should提取任何.jar 文件。 But since you want to use nodeJS to do it, you can make use of the exec function present in the node js code module called child_process .但是,由于您想使用 nodeJS 来执行此操作,因此可以使用 node js 代码模块中名为child_processexec function 。

you can create a simple function which takes in the path to the jar file like您可以创建一个简单的 function ,它包含 jar 文件的路径,例如

const exec = require('child_process').exec;

extractJar(path) => {
  const command = `jar xvf ${path}`;
  exec(command, (err, stdout) => {
    if(err) console.log(err); return;
    console.log('success!');
  })
}

alternatively, you try by using libraries like unzipper , these do not depend upon your operating system tools as the exec command just executes the process on your shell, but these libraries use your node js IO operations for extracting.或者,您尝试使用unzipper之类的库,这些库不依赖于您的操作系统工具,因为 exec 命令仅在 shell 上执行该过程,但这些库使用您的节点 js IO 操作进行提取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM