0

I am building a java application, which at some point utilizes an external exe. At this point, I'm trying to simply add this exe as some sort of library, which I can use in process call, so user wouldn't have to install it..

This exe file is an command line tool which produces some output, which is further processsed by the application.

So my question is, how does one include exe file within a java application, instead of calling it as a system process. Also acceptable would be, if this exe would be for example in the final lib folder, where java app would fetch it and execute it.

I hope it is clear and thanks for any help.

1
  • 1
    Put it into the jar as a resource which you extract to temporary location and run it from here. I don't think you will be able to run it from the jar directly. Commented Oct 24, 2015 at 21:07

1 Answer 1

1

Java interacts with other (native) code in a couple of ways:

  • to specifically coded libraries through Java Native Interface (JNI)
  • to external tools by forking a child process using Runtime.getRuntime().exec(...)
  • through network communications

In the first case, it is useful to include your JNI library with you Java program. It's thinkable to include it as a class resource in your JAR file, but that would be against the ideas of JAR files (holding classes and resources). More likely you should bundle the library (for all target platforms) with some sort of installation package (e.g. InstallAnywhere or others)

In the second case it's not useful to include the binary into your Java program (i.e. in the JAR file). Rather it most likely has (should have) its own installation procedure and your Java code should use an appropriate commandline (PATH) to find the executable.

I think the third case is not relevant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.