Eclipse - How to find out which libraries your project actually uses - java

I installed ZK Studio plugin for eclipse and have used it to create a new ZK based webapp. However, inside my /WebContent/WEB-INF/lib folder, there are a number of .jar files that were included automatically (beloning to the zk framework). I'm assuming this was done by selecting "create a new ZK project". However, when it comes time to deploy this to the webserver, I only want to include the libraries I actually need and use. Is there a way of finding that information out so I can shrink the size of my .WAR file?
Thanks!

These are called "transitive dependencies" - libraries that required by libraries that you use. The libraries that you use can't work without their dependencies, so ultimately you need all of the jars in WEB-INF/lib.
Maven is a dependency-management tool that tells you what are the transitive dependencies, (via a dependency graph). I would recommend using maven, although it would require some effort to introduce it in the current project.

Take a look at The Content of ZK Binary Distribution
then you can remove the library you don't need :)

Related

How to add source files of library jars?

I am using Eclipse IDE and its derivative like Spring IDE for Java development.
In a web application project, I add external jars like Spring MVC jars, Apache commons jars etc to the Web App library folder, hence they are automatically added to the build path. There are many jars in the Web App library folder.
I want to create folder in the project and add all the source files (zip/jar) of the libraries included in Web App library folder, so that I can navigate through the source of libraries from the Java editor window. Whenever I add a source zip/jar file to this folder, Eclipse should detect it and use it whenever I want to navigate to the source of a library.
Is the above possible in eclipse?
Note: I know how to add source files
for each individual jar by navigating
to the build path window and
specifying the source location. But
this is very crude way, and I need to
do for every library individually.
Also the drawback is that source path
is absolute, which means if I import
the project into another computer then
I need to create the source path or
even worse I might have to add the
source files individually again.
One way to automagically get the sources for the jars would be some kind of dependency management system. Most people would scream Maven (2/3) by now, but others exist and work well. Maven does have nice Eclipse integration, so that should be a plus.
The downside is that setting up a Maven project just for it's dependency management can seem overkill. Another point is that all the jars you depend on should be "Mavenized" as well.
As far as I know Eclipse wont automatically detect/scan source archive files and link them up to libraries in your workspace in the way you described it.
I agree with #Gressie on using Maven and the Eclipse Maven plugins -- as in that case it's just a matter of ticking a few boxes and Maven will do that for you.
If however your project is not Maven-ized, you can still do this in Eclipse but it's more tedious:
for each one of the jars in your project (which appear under the dependecies section) right click on it and select properties
in the dialog that pops up you have (at least) 2 locations you can configure: java source attachment -- simply browse to your jar with the sources -- and also javadoc location (point it to the jar with javadoc if you want the javadoc to appear as a tooltip when you hover the mouse over one of the classes/methods/etc in that library).

How can I debug external JAR files

I'm using some apache libraries in my code. At the moment I'm hitting a variety of problems that I need to debug. However the problem is when I pass data into one of said Apache libraries, when I try to step into the method call using netbeans it simply does the processing in the background and doesn't step into the code I want to view.
Does anyone know how I configure the IDE so that I can debug the apache code as well? Right now I just associate the JAR's with the project by adding them as libraries.
You need to attach a source jar (e.g. commons-lang-2.4-sources.jar) to your dependency, instructions here
I should also recommend using Maven2 to manage your project dependencies, I've not used Netbeans for at least 5 years, but both Eclipse & IntelliJ have Maven plugins which will import all your dependencies and link them to sources/javadoc jars automatically.

adding user defined libraries to SVN

I am developing a project for which I have used a number of external libraries (in jar format). I have added all of the external jars I have downloaded and added to the build path to our version control (subversion) as well.
However it has recently come to my attention that a number of the libraries are not in the SVN tree. I have looked into it a bit, and these are the libraries that I have created as user defined libraries and added to the build path in that way, following the instructions on the respective web pages. When I right click on them in Eclipse, I don't see the options to add them to the version control. So I decided to export them to the lib folder I have on the SVN tree. I am not sure if it's the right way of solving this problem, would appreciate som help on the matter.
I am not sure if it's of any help but the packages in question are: Commons Math, JFreeChart and JCommons.
Have you considered using something like Maven or Ivy for your external dependencies?

How to manage Libraries/jar files in eclipse?

I might be missing something but how do you manage Java projects in eclipse that need a lot of Jar files. I know maven manages libraries well if there are new updates but maybe I'm missing something, is there a way that eclipse can update new jar files (it would be especially useful for projects using apache-commons, say).
I don't want to sound like asking for a feature request, but I'm looking at if there are ways to keep libraries jar files that a Java project uses to keep them updated automatically the way maven does. With more languages coming with this type of features, finding the right Jar files probably should be easier than this.
Eclipse doesn't manage your jar versions for you, and as far as I know it won't do any auto-updating of jars that have newer versions out there. There's simply not enough information or infrastructure for Eclipse to recognize that a given jar you've added to the classpath is eligible for updating and that you want it updated.
However, there is a Maven plugin for Eclipse called M2Eclipse, which will read a POM and construct a classpath out of jars it finds in the local repository and any remote repositories you've configured. It behaves largely like Maven does in terms of finding the latest version for a given jar (if you've specified a version range in your POM).
You can create user libraries and change their content when new versions are available. That way you do not at least need to change the build path of every project. Or you can load sources of the libraries from their svn and use their trunk version. Remember that you can select multiple projects and svn update them at once.

How do I make Eclipse automatically include jars I place in my WEB-INF/lib folder into my project?

When I was doing JSP/Servlet programming, whenever I dropped 3rd party libraries into the WEB-INF/lib folder, they were automatically included in the project classpath. In GWT, this is not the case. Anyone know why? I loved how easy this was in JSP and I'd like these jars to be included automatically the same way.
If you are using the Google Plugin for Eclipse then my understanding is that a Google Web Application Project is just not the same animal than a Dynamic Web Project and thus behave differently. So if your project depends on libraries not provided by the GWT and App Engine SDKs, you'll need to put them in war/WEB-INF/lib and to add them explicitly to your Java build path.
In Eclipse Galileo, right click the web project and select build path then select the Java EE Module Dependencies and add the jars.
There is a plug-in technique that may help you if you want a directory where new jars are automatically updated in your build path, see this other post:
Eclipse buildpath automatically taking all JARs of a internal directory
The reason it works like this for your JSP's is because that is how the Dynamic Web Project was made to behave.
"If you remove a library path entry but not the JAR file, the library entry will be re-added to the path automatically." from http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.wst.webtools.doc.user/topics/ccwebprj.html
You could adopt Maven and use the Maven Eclipse Plugin; this plugin would update your classpath whenever you add a dependency. There may be a similar plugin for Ivy.

Categories