Jones Jones - 1 year ago 80
Scala Question

Can I package an external tool with my program?

I'm relying on shell calls to

(LGPL) for an important part of a project I'm working on: specifically, opening
files. The problem I have is that there is no guarantee that I will be able to find it on a user's computer (assuming it's even on their computer).

Is there some way to keep its binaries inside my compiled tool, so I don't have to worry about calling them externally? (I have the impression that this is what jar files are for, but I'm not sure.)

Or if that's not possible, what is the standard way of going about this?

Answer Source

Typically speaking, this is where you would want to get a library dependency to handle the unzipping of files. Some people use Apache Commons Compress, which would require this library dependency in your sbt build definition:

libraryDependencies += "org.apache.commons" % "commons-compress" % "1.5"  // Or whatever version you need

Alternatively, you can include the exe file in a resources file that will get included with your build - assuming that the executable doesn't need to be installed at the system level. This can be as simple as creating the src/main/resources directory and putting the file in there. Your jar will only work on compatible system architectures, though, so think twice before going this route. Unless there is a specific reason that 7-zip needs to be used to unpack the file, it's better to use a Java or Scala-compatible library and avoid having to make the shell calls.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download