Currently I am working on a tool for my masterthesis which uses Z3. I have chosen to use the Java bindings within my Scala project. Now I would like to create a distributable jar which may be used both standalone and by other projects. Unfortunately, I have not been able to find a simple way to do it as the com.microsoft.z3.jar uses native libraries such as libz3.{so,dylib,lib,dll}.
Normally, native libraries have to be linked by adding the -Djava.library.path=... flag specifying where the native libraries may be found.
I have been looking at SBT pack, assembly and one-jar but none of these packaging tools seem to allow reuse by other projects and link the native libraries automatically; also when my project is used as a library.
Ideally, the result is a .jar where the native libraries are included and Java knows where to find them (java.library.path) without the user having the specify anything. The .jar itself may be executed or imported as a library by another project.
Would I have to fallback to a situation where the flag -Djava.library.path=... has to be included for each project using Z3?
Any suggestions are more than welcome! Thanks!
Related
For context, I don't work a lot with Java, but need to create a Java maven package to provide a simple java wrapper around a cdylib (dll and so files). The dll size is relatively large, and I've seen some posts that there's issues loading DLLs from and to the running JAR if it's just a file that's included in the JAR archive.
So I'm curious if the Java devs out there expect Java maven packages to behave a certain way where DLLs/large-resources are concerned? Is there an expectation it would handle attempting to download the larger dependencies at runtime and just provide settings to override/control that behavior? Or should I just document it as needing those files and where to find them for package consumers?
If there's an expectation they would come bundled in a JAR, I also have yet to find any examples of how to create platform specific package builds from a shared codebase, only changing resources in Gradle, and would welcome any help on how to do that.
NetBeans allows the programmer to add a library and a jar file.
What is the difference between a jar file and a library? Is library similar to GAC assembly as in Windows.
There are similar questions, but they are way too specific and I was not able to understand the difference.
to put things very simple : library is a collection of jars
You could like create a global library java-ee which contains all Java EE related jar files. Then you could use this global library in your different projects. It will be simpler to manage them; and adding in new projects.
A JAR serves the same function an an Assembly in the C#/.net world. It's a collection of java classes, a manifest, and optionally other resources, such as properties files.
A library is a more abstract concept, in java, a library is usually packaged as a JAR (Java ARchive), or a collection of JARs.
A jar file is zip archive containing among other files, the java class files. A Netbeans library contains resources required by the project, including jar files.
If well understood: A library is simply a folder that groups classes. For example in JDK, a library present there is a group of classes stored together.
If not mistaken a .jar file is a group of compiled classes in .class format and was created by Java creators so a program will be OS independent; which means within a JVM you will run your app in .jar format on a Linux, Windows, etc without re-coding tour app for various OSs.
This article explains it all..
It states
Java's libraries are commonly known as class libraries. However, Java
refers to class libraries as packages.
I'm trying to create a Dll out of a scala-class. I'm using IntelliJ together with SBT. I've already found a way to convert .jar files into a Dll, using the ikvm-converter. Now the problem: When I use "package" under SBT to create a .jar file out of my .scala file and try to convert it afterwards with ikvmc into a Dll the resulting library is empty when integrated in C#...
For example converting the Jama-Library (which is written in Java) works fine, where converting Scama (written in Scala) does not work.
Is there a way to do this conversion of scala code into a dll? Is there a "Scala to Java"-conversion tool?
Best Regards,
Christoph
I have no knowledge of .NET, but judging from SK-logic's and your comments to the questions: sbt package does not include the Scala runtime library, because it assumes you are going to export your project as a library to be used within other Scala projects.
Therefore, you will need to create a "fat" jar that contains the runtime. For example, in this blog you can see how the author creates a fully self-contained executable, by converting both the project jar and the runtime jar.
There are different tools to do that with sbt. The easiest would be sbt-assembly, but you will end up with a very large file, because it just adds the whole runtime. If that is a problem, you may want to filter the runtime instead, using the proguard plugin. More on this topic in another StackOverflow entry.
I have created mytest.jar file with library that contains near 30 library files also jar.
Is it possible to put all library jars inside mytest.jar so that I need to distribute only 1 jar?
May be it can be done using manifest?
Thanks.
Loading classes from jars-inside-jars is not possible with the standard Java classloader. However it is possible using a custom classloader, this is how for example UberJar works.
The maven shade plugin takes a different approach. It will unpack all the jars you depend on, and pack them (along with your own classes) into one big jar. Then the normal classloader can be used. This is simpler, and is also possible without maven using jarjar.
Not out of the box. However, One-Jar provides a solution. It works fine for standalone apps, which is what I assume you' re making.
If you're making an applet instead, One-Jar won't work.
Usually one uses a jar repacking tool like jarjar for this purpose.
I'm going to deploy a Java application with a custom launcher, and I need to have all the classes needed for my app in a single jar file so I don't have to deploy the entire Java SE libraries with it.
I was thinking of using some pre-existent ant tasks to create a target that recursively searches all my compiled classes files for its dependencies. After all the dependencies have been determined it would extract the needed class files from their JAR's, copy it along with my classes to an output directory and make a single jar from it.
If there's no such thing avaliable out of box, I can create one myself, but I need to know how references to other classes are stored in .class files. It could be much easier if there's some kind of java library like .NET's Mono.Cecil/System.Reflection that exposes an high level API for inspecting/manipulating Java.
Since I'm new to Java, I'm having some trouble in finding what is needed to acomplish those things. Can someone give me some direction?
Unfortunately, you cannot ship only part of Java SE - that will breach the license agreement. If you use Java SE, then all of Java SE must be available.
The simplest way to achieve this is to use an Ahead Of Time compiler. These take care of packaging only the classes you need, and adhere to the JDK license agreement by making the "unused" parts of the JDK available via optional download.
For example, Excelsior JET is a good AOT compiler and will package just the classes you need. It's not free for commercial use, although open source projects can apply for a free license grant.
Alternatively, you may simply assume that the user has the JRE already since it's installed on over 90% of desktops, and in cases where the JRE is not available, have your installer download one for the user. AdvancedInstaller has a free edition that will accomplish this.
After all the dependencies have been
determined it would extract the needed
class files from their JAR's, copy it
along with my classes to an output
directory and make a single jar from
it.
As an easy solution, if you use Eclipse IDE you use the following solution:
Under the Java project properties (right click):
Export... => Export as Runnable JAR
The exported JAR will have all its dependencies packed into it.
alt text http://www.ubuntu-pics.de/bild/97131/selection_016_mg6IDm.png
Here is one suggestion I found on the web:
<jar destfile="${build-abc}/abc.jar" duplicate="fail" index="true">
<zipfileset src="${compile-lib}/demo.jar" includes="**/*.class"/>
</jar>
This should add the dependencies to the jar (as shown with demo.jar). You still have to adapt the manifest file so that the added jars appear on the classpath.
This doesn't solve the 'Java SE' classes problem - you'll have to bundle a jre in the installer package or depend on an existing one on the target system.
You won't have to deply Java SE classes, as they already are in the customer JRE.
If your dependencies are expressed ion a common way (through Maven or Ivy) i guess it's quite easy to find an equivalent of maven uberjar task ... which will do what you want to do, but in a more simple way (as it simply repacks all jars in one big jar).