At build time, there are tools like Maven and Gradle. These allow your dependencies, and the tool builds the dependency graph to determine the required transitive dependencies. Both Maven and Gradle represent the dependencies in directed acyclic-graph, but Maven's DAG is far more constrained than Gradle's. Maven is very declarative, specified in XML, and is very much our way or the highway. Gradle is very flexible, with build scripts specified as Groovy programs. Here's a feature-by-feature comparison (biased towards Gradle).
As far as Maven is concerned, all you have to do is:
mvn clean install
If you want to visualize the dependency graph:
mvn dependency:tree
At run time, it's a different story.
Typically, Java applications are bundled into WAR or EAR files. These are glorified ZIP files which contain the application and all of its dependencies. A WAR file looks like this, unpacked:
+-+ WEB-INF
| |
| +-- classes
| | \_ application specific classes
| +-- lib
| | \_ bundled JAR files for required dependencies
| +-- web.xml
| \_ main web application configuration
+-- ... web assets
WAR and EAR files are deployed onto an application server (Tomcat, JBoss, etc.), which manages shared dependencies between applications.
Outside of application servers, it's a bit tricky. The simplest approach is to install the application as an executable JAR file with all of its dependencies installed along side it. JAR files can have a "MAINFEST.MF" file included with it that lists all of the dependent JARs. A build tool like Maven will automatically configure the JAR to reference its dependencies and package the application and its dependencies in a ZIP file (see the Maven assembly plugin).
Another approach is the so called "fat-JAR" or "uber-JAR" which is a JAR containing other JARs or the main JAR simply has the exploded contents of the dependency JARs (see the Maven shade plugin).
Finally, there is OSGi, which manages dependencies at runtime. OSGi is an open standard, implemented by containers such as Apache Felix or Eclipse Equinox. Here's an idea of how to set up an Eclipse Equinox application. You develop your application as a "plugin" into one of these frameworks. But, as a nice benefit, you can manage multiple versions of dependencies and even get auto-update.