I’m making an executable JAR that uses the RxTx serial library. It requires access to rxtxSerial.dll and I want the JAR to put it there automatically. That way I don’t need an installer — just a standalone JAR. Can this be done?
When I call new FileOutputStream(new File(“C:/Windows/rxtxSerial.dll”)), I get the following exception:
java.io.FileNotFoundException: C:\Windows\rxtxSerial.dll (Access is denied)
Thanks,
Neal
Permissions will prevent you from writing to system directories in modern versions of Windows. Even if the system let you do it, it would not be good practice.
By packaging your app with One-Jar, you can bundle your native libraries inside the jar, and they will be expanded and added to the classpath at runtime.
It is easy to integrate into an Ant or Maven build. As a bonus, you can also include any dependent libraries and other resources within the jar, and they will all be expanded out to temp files at runtime.
In ant, repackaging your existing jar would look something like this: