簡體   English   中英

使用 NodeJS 提取.jar 文件

[英]Extract .jar file with NodeJS

我需要使用 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提取任何.jar 文件。 但是,由於您想使用 nodeJS 來執行此操作,因此可以使用 node js 代碼模塊中名為child_processexec function 。

您可以創建一個簡單的 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!');
  })
}

或者,您嘗試使用unzipper之類的庫,這些庫不依賴於您的操作系統工具,因為 exec 命令僅在 shell 上執行該過程,但這些庫使用您的節點 js IO 操作進行提取。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM