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.
Advertisement
Answer
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. 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
.
you can create a simple function which takes in the path to the jar file like
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.