Including External Libraries in Exported JARs Using Eclipse
When developing a Java project that relies on external libraries, exporting the project as a JAR (Java Archive) often requires including these dependencies for proper execution. In Eclipse, there are two main approaches to accomplish this:
Exporting as a Runnable JAR
- Right-click on the project in the Package Explorer.
- Select "Export..." from the context menu.
- Choose "Runnable JAR File" as the export type.
- In the "Runnable JAR File" dialog, go to the "Libraries" tab.
- Select the option "Package required libraries into generated JAR".
- This option will automatically include all dependencies found in the build path.
- Click "Finish" to export the JAR.
Exporting as a Regular JAR
- Right-click on the project in the Package Explorer.
- Select "Export..." from the context menu.
- Choose "JAR File" as the export type.
- In the "JAR File" dialog, go to the "Libraries" tab.
- If the desired external libraries are present in the project folder, they can be included by checking the corresponding checkboxes.
- However, external dependencies such as those managed by Maven cannot be included in this way.
- Click "Finish" to export the JAR.
Notes
- When exporting a runnable JAR, the "Launch Configuration" dropdown will allow you to specify the main class to use when executing the JAR.
- External dependencies downloaded through Maven or other build tools may require additional configuration to be exposed to the JAR.
The above is the detailed content of How to Include External Libraries in Exported JARs Using Eclipse?. For more information, please follow other related articles on the PHP Chinese website!