What is the difference between runnable jar library handling options? - eclipse

So I will be using Java Web Start to deploy the java application. When exporting to a Runnable Jar, there are three options in eclipse Helios.
Extract required libraries into JAR
Package required libraries into JAR
Copy required libraries into sub folder next to JAR.
What are differences, and how will they affect my .jnlp file?
If it's a single jar, isn't it easier because I wouldn't have to write all the different paths to all the libraries it uses?
If there are changes in both the library and the application, a single jar would be a better solution? Or would I need <jar href=''> for each individual libraries?
Also note that I need to make use of native libraries like .dll and .so files.

Extract required libraries into JAR - Extracts the actual .class files from the libraries your app uses and puts those .class files inside the runnable JAR. So, the runnable JAR will not only contain the .class files of your application, but also the .class files of all the libraries your application uses.
Package required libraries into JAR - Puts the actual JAR files of the libraries into your runnable JAR. Normally, a JAR file within a JAR file cannot be loaded by the JVM. But Eclipse adds special classes to the runnable JAR to make this possible.
Copy required libraries into sub folder next to JAR - Keeps the library JARs completely separate from the runnable JAR, so the runnable JAR will only contain the .class files of your application.
Option #2 is convenient because it packages everything neatly into a single JAR, and keeps the library JARs separated from your application's .class files.
However, a downside to packaging everything inside of a single JAR (options #1 and #2) is that, if you update your application, then the user will have to download more data to update the application. If the JARs are kept separate, then the user would only have to download the JAR that contains your application code, instead of a single, massive JAR that contains your application code and all the library code.

Related

sbt for web app with command line code

I'd like sbt to generate two packages:
A WAR file, for the web app
A JAR file, which has command line and batch code
The two packages share a lot of similar code (the business logic) and dependencies, but of course the Servlet aspects are only in the WAR, and the command line and batch only in the JAR.
I'd like the JAR to run by itself, no external dependencies required (ala sbt-assembly).
How can I do this?
WAR file
You can make a war file using earldouglas/xsbt-web-plugin and use sbt-assembly for fat JAR. You might have to get a bit creative to include some files in one but exclude from the other.
Generating JAR and WAR from the same code base
If the resulting packages contain different library dependencies at the end, for example including Jetty or Netty for standalone JAR, I think it needs to be a separate subproject. See Multi Project builds.

get Eclipse to export libraries as a jar

How can I get Eclipse to export as a non-runnable jar all the contents of JRE System Library [JavaSE-1.6] and Referenced Libraries?
I want to use -classpath to bring together several jar files rather than use Eclipse's Export > Runnable JAR file. Motivation: swapping out a single class that happens to be in a package of its own, by swapping the jar.
It's easy enough to export my own packages in (non-runnable) jars but now I need the "library" classes as well and I have not found an easy and obvious way to do that.
There is an option when you export a runnable JAR to "Copy required libraries into a sub-folder next to the generated JAR". Would that work for your case?

Why is the Eclipse jar file generating compile errors when the application does not have errors?

I'm trying to produce a jar file of my project using Eclipse and when I try to use it it is giving me errors as certain files are not being included in the jar file. I recompiled the project again and after generating the jar file it states that "Jar file export finished with warnings" and certain files are exported with compile warnings.
Is there another way to generate a jar file ? I tried using netbeans but its not allowing me to import the project
You can check in the project properties for the dependencies that you're using in your project environment (Project -> Properties -> Java Build Path).
If all the necessary dependencies are not included in the JAR file that you're creating and also not available on the classpath of the target system, then such errors will occur.
You can either pack the required dependencies in your JAR or deploy them separately to your target system - which method you use really depends on whether the dependencies are 3rd party libraries (they should be deployed separately) or home-grown components that are part of the system itself (they should be packaged together).

Creating a JAR file, some classes are missing

I'm creating a JAR file in Eclipse and for some reason classes are missing. The classes that are not included are referenced in other JAR files included on my build path. What doesn't make sense is that the behavior is not consistent. Some classes on the build path get included while others do not. Any ideas?
The step I take to create my JAR file, is to export all the source folders.
JAR files are libraries, and that means - thinking object oriented:
If the classes are referenced in other JAR that included in your build, so they have to be part of the included JAR files and not part on your new JAR.
That's the whole idea of a library - If I understand your question right.
If your JAR uses those external classes, so you have to include those classes's JAR files in your project.
I hope I understood you correctly.
When I need to distribute something for internal use, I use the Maven assembly plugin: it allows you to create jars with dependencies. This is very useful if you only want to pass around one single jar: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

Is it possible to recompile a single .java Java file without having the whole project?

I have this .JAR file. I decompiled it to multiple .java files. There is any way to have a new functional .JAR file, after updating a single .java file and recompiling it? If it is possible how would we recompile this .java file without having it's dependencies? (ie. external libraries)
Of course!
Ask javac to
javac -cp <whatever classpath you have> path/to/YourClass.java
after that you would say
jar uvf yourjar.jar path/to/YourClass*.class
and you're done, your .jar have been updated, now deploy it!
Remember, .jar file is just a zip archive with classes and manifest!
If your java source references any external classes, you'll need them around. But you also need them around for actually using the compiled class, so I guess it's not a huge problem.