Adding external jar in eclipse - java

I have a java main project and a java library project which is added as a library in the main.
The library has some .jars with essential content for both (the main and the library). I thought the main project could access these jars, but apparently not. Am I correct?
So... I thought I would have to dupplicate the .jars from the library and put them also in the main project. But this is quite awful. So I found the "Adding external .jar" from eclipse which let me add this .jar from the library, but my question is: "What will happen when I build an unique .jar? Will the .jar be added to the library and also to the main dupplicating itself?"
Also, can I import as a library an open project wihout having to compile it into a jar and be able to edit the project in real time?
Thanks

When you build a unique jar for your own code, it will not include the classes from the other jar. If you want other people to run your program, they will either need that jar themselves, or you will have to distribute the additional jar with your own jar (assuming that's allowed).
You could unpack the jar on which you are dependent and put it in your own jar, but this is unusual and not recommended. If the people who wrote that code corrected bugs and distributed a new jar, people who got their new jar would get the fixes and improvements, but not people who were using your packed version unless you distributed a new one.
I have no idea what your last question means...

You can certainly have one project depend on another, which sounds like what you mean by "can I import as a library an open project wihout having to compile it into a jar and be able to edit the project in real time?".
To share the jars from the library project, go to the "Order and Export" tab in the Build Path dialog, and tick the jars you want to make available.

Related

is there a way to make changes in jar which doesnot have source code in it and rebuild it as a jar in eclipse?

Is there a way to make changes in jar which doesnot have source code in it and rebuild it with this change as a jar in eclipse.
You can look into using Java decompilers; in order to turn the .class files within the JAR archive back into .java source code. The process and some tools for that are outlined here.
But: understand that *decompiling" can be a tough business! Plus: there is always the question if the licence terms of the library you are using allows you to do that. Being able to do something isn't the same as being allowed to do that!
Finally: keep in mind that a JAR is just a deployment artifact. A lot of libraries are open source, and you can most often download that source and build the corresponding JARs completely on your own.

Jar file too big

I created a simple project using WindowBuilder in Eclipse and my goal is to send it by email. I don't know what kind of computer the person is using, so I exported my project into a 'Runnable JAR File' and checked the option 'Extract required libraries into generated JAR'.
The problem is that the generated JAR file is 20MB in size!!! The project has only one simple window - nothing complicated or fancy.
I found that some people use ProGuard to include only what is really needed.
I would like to know if there is a way to optimize it 'manually'? Are there libraries that are automatically included when creating a WindowBuilder project, and how may I determine which libraries I can remove?
Thank you.
I've had the same Problem using WindowBuilder. My solution was to look for the imports in my .java file, e.g.: import org.eclipse.swt.SWT;
In the Project Explorer in Eclipse you can see that there are much more imports than needed. Those 'Build Paths' can be removed carefully.
Simply rightclick on a .jar import like "com.ibm.icu_52.1.0.v201404241930.jar" and click on "Build Path" and "Remove from Build Path". Unfortunately, you can't remove or delete the packages inside the .jars.
But using this method, I managed to reduce the size from 20.7MB to 3.87MB. It's something...
Like fge said, send the source. Or upload the .jar to dropbox if you require you partner to access all of the files in the .jar.
If you don't like dropbox, find some other cloud storage solutions through a google search. Github or Bitbucket could also be an alternative to dropbox.
Cheers.
Use the Eclipse plugin FatJar. FatJar shows you which libraries are getting imported and allows you to specify which .jars, libraries, etc., that you want built into your JAR.
FatJar
Your jarfile is too big due of the project template. Create a sample java project, then use windowdbuilder components. Do not create a project Swing Template, by this way eclipse is gonna import all eclipse gui toolkits.
Tried it out with my way, my application's length equals to 3Ko against 24MO with the template project

Eclipse - checking that all libraries are imported

I have a project that uses a lot of external libraries (mostly .jar files). I am using Eclipse Helios Service Release 2.
When something doesn't work, the problem is usually caused by missing jars or some problem with classpath. What I have to do, is to check that all necessary jars are correctly included in my classpath.
The problem is that I have several libraries imported + external jars (in case of libraries, the classpath only points to the directory with the jars) and Eclipse provides no easy way to search for included jars. If there was any kind of function that would work like this: "search for xyz.jar" and find if the jar with given name is already included somewhere, instead of manually controlling this, it would be a great help.
It would also help if Eclipse provided a function to sort all the jars and libraries by name instead of displaying them in the same order they are specified in path (I mean only in the project manager, of course).
So my question: is there an easy way to check these things or do I have to do that manually? I have cca 30 jars to include and cca 300 already there and this is a real pain...
You could use a build environment, such as Maven, to manage your dependencies for you. Then Eclipse does zero thinking on its own and your life becomes far more pleasant (particularly when the time comes to package your code for release).
I couldn't imagine managing 300+ dependencies any other way.

Load whole project from Eclipse(about source code)

I am working on buid a plugin of Eclipse. In one step, i load the project through scan classpath,but the feedback from requirement is:
Loading projects encompasses two things:
Loading multiple files from the same
directory/package
Including files from other packages through for instance Eclipse's .classpath files
Since the prototype will be built into an Eclipse plugin anyways, is it fine to use Eclipse stuff, like the .classpath files? you are now loading and reading these files yourself. It might be more convenient to use Eclipse code for this, since it has to be already there.
I have no idea how to deal with it from Eclipse, can anybody help?
I think you're looking for PDE build. You could have a look at this tutorial.

searching through .jar files eclipse

I'm porting a few java gwt projects into eclipse and the projects depends on many external .jar files, some of the dependencies seem to be dynamically linked so eclipse isn't picking up the missing links while running the ide.
At run time, I often get exceptions that say for example 'import bar.foo.XML' is missing or some FooBar class definition is missing and it always takes me a while to figure out which .jar file these classes/libraries belong to so I can add them to the run path.
Is there a quick way to search which .jar files contain what classes and what other library they depend on?
An oldie, but still good, and integrated into eclipse:
JarClassFinder:
Update 2013: the project still exists in a different form as an independent app JarClassFinder.
In term of Eclipse plugin, it is no longer maintained, and you only have variant like "BundleclassFinder".
Other (manual) ways to find a class within jars: "Java: How do I know which jar file to use given a class name?"
You need a tool like Jar Analyzer
Can't you just mark all the jar-files in Eclipse and right-click->add to Build Path?

Categories

Resources