ANT Java-Jar task to include native DLL - java

I have a JAR library that needs a native DLL library to work properly (Scriptom/Jacob).
I added the JARs to my classpath in ANT. But I do not know how to add a DLL file so my compiled Java/Groovy files finds them (neither in a generated JAR, nor in an ordinary execution by java Main.class). They are all located in a project subdirectory libs.
How do I have to alter my ANT build file that DLLs are recognized by my application?
PS:
As it works properly in a configured Eclipse environment: Is it possible to extract a fully working ANT build file from an Eclipse Run Configuration?

You can't use DLL files when they're still packaged in the jar.
I suggest you create an application folder where your .jar will be located at and next to the .jar, put your DLL files there. In your application you will need to load your DLLs from that location.

Related

Configuring native libraries for EAR in Eclipse

I have a large project with multiple modules, which is deployed to glassfish using an EAR bundle (I'm using the Eclipse IDE).
One of the modules is an EJB project, which depends on a JAR library that depends on a some native libraries (DLLs). The DLLs are included in the jar
The problem I'm having is that the native libraries are not found. It seems that java.library.path doesn't contain the folder I configured in project Properties -> Java Build Path -> Libraries -> the jar -> Native library location.
Is there something I'm missing?
I haven't found a solution, but I found 2 workarounds.
Embed the DLLs into the JAR / EAR / WAR, and load them using this loader, which basically gets the DLL using the Class.getResourceAsStream method, copies it in a temporary directory, and loads it from there (this is the method I chose).
Add the DLLs to system $PATH. Either put the folder where they are located in the $PATH environment variable, or copy them in a folder that is in $PATH.

How to add Sikuli's dll files to a runnable jar file

I have used Sikuli java .jar to test a website, now I need to make a runnable .jar file and give it to my costumer, but I do not know how to add Sikuli's dll files to the jar in a way that it does not change any thing on the costumer's computer. I am using Eclipse LUNA.
To add sikuli libraries with your java program's jar , you should add sikuli java.jar into build path path of your java project in the eclipse platform.
then export your project. It will add sikuli lib into your exported jar.

Netbeans: how to create an executable .jar file with all libraries and resource files included?

I tried clean and build and found a .jar file in the dist directory. However, the libraries and resource files the program needs to run properly are absent in the .jar file. One workaround is put all libraries and resource files somewhere in the same directory or sub-directory of the .jar file. It is very inconvenient. How can I inject everything into the .jar file?
See the NetBeans documentation on Packaging and Distributing Java Desktop Applications, especially the section on Running and Distributing the JAR File.

How to build a distributable jar with Ant for a java project having external jar dependencies

I have a Java project in Eclipse with class MainClass having main method in package :
com.nik.mypackage.
The project also references two external libraries, which I copied in the lib folder in Eclipse and then added to build path using ADD JAR function. The libraries being one.jar and two.jar
This library is in lib folder in eclipse and added to the build path.
I want to create a executable JAR of the application using ant script. So that user can access my application using command:
c:>java -jar MyProject-20111126.jar
I know about the Eclipse plugin which directly exports a java application as runnable JAR. But I want to learn ant and the build process so manually want to create the build.xm.
You have two options from your build.xml. You can either unjar the library jars and then bundle their contents with the code compiled for your application. Or, you can put the library jars on the filesystem and supply a ClassPath entry in the manifest file of the MyProject-2011126.jar file.
If you set the classpath in the manifest remember that the path you supply is relative to the MyProject-2011126.jar.
one alternative:
Instead of having only a jar, you build mutiple jars (your jar + libs) +batch file.
So, your built package can be like this structure:
-/package/bin/app.bat
/package/lib/my.jar
/package/lib/one.jar
/package/lib/two.jar
In app.bat you just have the same as your code
java -jar MyProject-20111126.jar
PS: if you want to start learning built tools, ANT may be a bit tool old. I suggest http://maven.apache.org/
Please try one-jar. It helps to redistribute everything packaged as single jar and comes with ant-task . See Easiest way to merge a release into one JAR file.

creating jar file for java application

i have created a java application which uses data from its config folder and , it also uses third party jar files those are located in lib folder, could anyone tell me how to create jar file for this project with the content stored in config file and lib folder.
i tried creating jar using eclipse export functionality. when i run this jar file, it says it can not find the third party libraries that i have used for this project and configuration file.
thanks in advance for any help
You can create a Runnable JAR in Eclipse 3.4+ in the Export wizard selection dialog (right click on a project and go to Export...) using an existing launch configuration which will incorporate the libraries or repack them. Config files should be readable from the same directory as the runnable jar is located. If you need any help with loading these in, just ask :)
(source: eclipse.org)
You have two options
include the stuff in the third-party jars in your jar
provide access to the jars on the classpath when you run your jar.
Both have their benefits and their drawbacks.
Java does not support putting JAR files inside executable JAR files, so you can't just put your third-party library JAR files inside your own JAR - Java won't be able to find them.
If you don't want to distribute your application as a whole bunch of JAR files, you can use a look such as One-JAR which will build a JAR file for you that contains your own classes plus the classes of the third-party libraries that you're using.
To learn more about how to package a program in an executable JAR file, see Packaging Programs in JAR Files in Sun's Java Tutorials.
If you use netbeans just by click on "build" a jar file will show up in the "dist" file in your project directory

Categories

Resources