get Eclipse to export libraries as a jar - eclipse

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?

Related

What is the difference between runnable jar library handling options?

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.

How can I use netbeans to export each package into separate jars?

Right now, netbeans exports all the packages in a single project into a single jar, I would like it to export a separate jar for each package, how would I go about doing that?
Would also like to know how can I include all my dependent libraries into the generated jar

Eclipse: Package multiple projects into one JAR

I have multiple projects but only one with a Main class. The one with the Main class depends on the other projects. These projects are referenced in Eclipse, but when I export my JAR, the other projects are not exported with that JAR.
How can I export my Main project and "include" the other projects into that same JAR? I'd rather not have several JARs and have to define them into my Classpath on the command line.
Don't do it the hard way. Use Eclipse's own exporter. First ensure that you've the other projects referenced as Projects in the main project's Build Path. Once done that, just rightclick the main project, choose Export and then Java > Runnable JAR file. Choose the launch configuration (which you used to test the main() class locally) and then you've 3 Library Handling options to package the JAR:
The first option will just repackage the classes of other projects inside the JAR. Everything is plain thrown together.
The second option will copy other projects as JARs inside the JAR. This does normally not work that way, but Eclipse also adds a special launcher which basically copies the embedded JARs into memory, extracts there, adds the files to the classloader and then invoke the main() with that classloader.
The third option is something you don't want for this particular case.
If I were doing it I'd 'mavenize' the projects, using a maven dependency for each project dependency and then use
mvn assembly:assembly
see http://maven.apache.org/plugins/maven-assembly-plugin/ for more on this plugin

How to export GWT project classes into JAR file

I find it difficult to export classes from one project into JAR file, so that I could import it in another project.
How do I try?
I right-click on project in Package Explorer -> Export -> Java -> JAR file -> select all the packages I need. 'Export generated class files and resources' option is checked, other options are left unchecked. Then I click Finish.
When I import such generated .jar file into the dependent I encounter a list of errors:
The import pl.abc.xyz cannot be resolved
Xyz cannot be resolved to a type
It seems like the classes from the JAR file were not found by the compiler.
Please correct me, if I do it in a wrong way. Thanks.
It seems that you need to include in jar also java source files from the client package (sometimes also shared package depending on your GWT module structure as defined in *.gwt.xml file).
The GWT compiler requires java source for the part which has to be compiled into Java Script, to be availabe as classpath resources along with compiled classes. It is simple to achieve with ant or maven build.
You can also check Export Java source files and resources when exporting, but it will add all the source code, not only the client part.
Make sure you inherit the module in your .gwt.xml file. You want to inherit the .gwt.xml file from the GWT jar you are importing, for example:
<inherits name="com.example.youmodule.Name" />

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.