Determining Java Project Dependencies in Eclipse

10,493

If you have your project set up in Eclipse, then you should be able to view all the dependencies in the Project Explorer view. They must be on the build path in order for you compile things properly.

On the Ant side, I would assume the necessary jars for the runtime will be copied somewhere with the rest of the build. This is especially true if your project is being built into a WAR.

If nothing is being copied over, then your best bet is to hunt down all the compile-time and run-time jars by carefully scanning your build.xml. This is something you should probably be doing anyway if you're converting it to Maven. I suppose the key parts to look for is the javac and java Ant tasks.

As a side note, as you're creating your pom.xml and adding dependencies, keep an eye on the dependency hierarchy by opening your pom.xml in Eclipse and clicking the Dependency hierarchy tab. This will hopefully keep you from adding redundant top-level dependencies.

Share:
10,493

Related videos on Youtube

Kris Schouw
Author by

Kris Schouw

Updated on June 22, 2022

Comments

  • Kris Schouw
    Kris Schouw almost 2 years

    This is an incredibly silly question, I know... But I'm in the middle of converting a Java Project once built with Ant to do so with Apache Maven, instead. One of the steps I've read to accomplish this was to place all of the JAR's the project needed in the pom.xml file as a dependency. Now, since I'm not entirely too familiar with this project, was there any property setting I might be able to look at to view all of the JAR dependencies clearly? I know some are in the WEB-INF\lib directory, but looking at the original build.xml file for Ant, there seems to be more than those it was trying to add. Again, I'm very new at all of these concepts, but I was just hoping for an easy way to determine what dependencies a Java Project has so that I can add them -- or their Maven-equivalent -- to the pom.xml file. Any suggestions?

    Edit: Here's part of what's confusing me. When I open the WAR file for the project that I'm trying to deploy with Apache Tomcat, these are the only JAR files I can find...

    images
    META-INF
    util
    WEB-INF
        > classes
        > lib
            > jtds-1.2.4.jar
            > jw-core-web-1.2.0.jar
        > web.xml
    blah.jsp
    blah.jsp
    blah.jsp
    

    I assume I need these two files, at least. But when I open the build.xml file, I find a section like this:

    <!-- Jars listed here are added to the generated war file -->
    <fileset id="bundle.jars" dir="WebRoot/WEB-INF/lib">
        <include name="base.jar"/>
        <include name="ldap.jar"/>
        <include name="junit.jar"/>
        <include name="titan.jar"/>
        <include name="activation.jar"/>
        <include name="javamail-1.2.jar"/>
        <include name="commons-httpclient.jar"/>
    </fileset>
    

    Granted, I didn't see any of these jars in the WAR file briefly expanded above. In addition, the JRE System Library is listed under my Package Explorer along with a list of JAR files. Now, do I need to add these to my dependency list as well? Here's what I've got:

    JRE System Library
        > resources.jar
        > rt.jar
        > jsse.jar
        > jce.jar
        > charsets.jar
        > dnsns.jar
        > dns_sd.jar
        > localedata.jar
        > sunjce_provider.jar
    
  • Jeremy
    Jeremy over 12 years
    This doesn't answer the question at all.
  • Kris Schouw
    Kris Schouw over 12 years
    Ok, I see what you're saying a bit better now. So the JAR's listed in my WEB-INF\lib are compile-time JAR's while those mentioned in the Ant build.xml file are run-time JAR's? Alright, well do I need to add them all as dependencies to the pom.xml file (keeping track of redundant dependencies, of course)?
  • Kris Schouw
    Kris Schouw over 12 years
    I see... I couldn't find the common.component file in the .settings directory, but I did manage to open the .classpath file in Notepad++. The only jar listed there was as such: <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jtds-1.2.4.jar"/>. Does this mean that the jtds-1.2.4.jar is the only dependency?
  • Kris Schouw
    Kris Schouw over 12 years
    Yeah, it took me a while to understand the purpose of switching over, but with all of the dependencies found on either the maven or our local, third-party repository, we don't need to lug them around everywhere. My problem is just determining which jar file littering the project need to be included as such in my pom.xml file.
  • Jeremy
    Jeremy over 12 years
    Whatever is listed in WEB-INF/lib is probably everything you need to build and run your web application. If not, then there will probably be a simple edge-case you have to deal with. (Don't forget to upvote answers you find useful, and to select one as the "best" answer!)
  • McDowell
    McDowell over 12 years
    @Kris I've added more detail. If the Ant-generated WAR works, then I suggest adding those libs as dependencies in your pom. Scope everything else as appropriate.
  • Kris Schouw
    Kris Schouw over 12 years
    Alright. It just seems weird to only have those two JAR files needed as dependencies. Anyway, I'd upvote certain posts, but I'm not a member and my work's proxy will not allow me to access the sites needed to create an account, lol.
  • Jeremy
    Jeremy over 12 years
    @Kris: You're not a member? You look like one.
  • Kris Schouw
    Kris Schouw over 12 years
    The .classpath file contains one JAR and two containers, it seems. I assume that I should include the JAR, but do I need to include the containers as well? If so... are their Maven equivalents for containers? Also, I don't seem to have a org.eclipse.wst.common.component file; I have a org.eclipse.m2e.core.prefs and org.eclipse.jdt.core.prefs file, only. Should I try to add what's contained in there as dependencies, too? Most of the things within the second file are listed like org.eclipse.jdt.core.compiler."stuff".
  • Kris Schouw
    Kris Schouw over 12 years
    Lol, nope. I've tried, but that whole proxy issues gets in the way. I've been meaning to make an account while at my home computer... I just keep forgetting.
  • Jeremy
    Jeremy over 12 years
    @Kris: You have a username and a profile. Your user id is 901093. I don't know how much more of a member you can be? Anyway, good luck.
  • Kris Schouw
    Kris Schouw over 12 years
    Yeah, any attempt to upvote or anything asks me to either login or register. At any rate, I finally managed to get my project built and deployed, so thank you very much.