In Eclipse, how can I export a package and all subpackages as jars?

I am trying to export a specific package and its subpackages as non-executable jars in Eclipse. I directly click on the package that I want to export, and click "Export." However, when I export the jar, it only exports the top-level package that I selected, and all its classes.

I want to export all subpackages with it automatically. The only way I have been able to do this so far is to actually select each sub-package (and their sub-packages, etc.) for export. Is there a way to select all subpackages for export also automatically?

Example (with image):

I want to export the package "bar1" as a can. I directly click on the package bar1, click "Export" and select JAR. However, the subpackage bar1, "util". Not selected by default and will not be exported. If I wanted to export the subpackages of bar1, I would have to select them separately. It is a pain if there are many packages. Is there a way for Eclipse to add the util subpackage for export when trying to export the package bar1?

enter image description here

+6
source share
3 answers

I think you have it right and there isn’t a lot of automation or an easier way by clicking on it to select a specific package and subpackages. However, I think you can use ant or maven to do this for you, which is significantly automated and simpler. Here is how you can select a specific package in ant:

<dirset dir="aDirectory"> <include name="a/package/**"/> <exclude name="**/package/to/exclude**"/> </dirset> 
+2
source

Go to file-> export-> JAR file, there you can select "Export generated class and source files" and make sure your project is selected, as well as all the folders under it! In addition, make sure that they are in the Assembly Configuration β†’ Order and Export area, and that they are marked for export.

If all else fails, try FatJar . It detects all the dependencies and automatically associates them with the JAR. In Eclipse, you can use FatJar using the Build Fat Jar option for Java projects.

0
source

The best way I've found is to set the Package Explorer view to Flat instead of the hierarchical one (triangle β†’ package presentation β†’ flat)

Then select all packages starting with bar1 , right click, export.

0
source

Source: https://habr.com/ru/post/947581/


All Articles