Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Eclipse, how can I export a package and all sub-packages as a jar?

Tags:

java

eclipse

I'm trying to export a specific package and its sub-packages as a non-runnable jar in Eclipse. I right click the package I want to export and hit "Export". However, when I export the jar, it only exports the top level package I've selected and all of its classes.

What I want is to export all sub-packages with it automatically as well. The only way I've been able to do this so far is to actually select each sub-package (and their sub-packages, etc...) for exporting as well. Is there any way to select all sub-packages for exporting as well automatically?

An example (with image):

I want to export the "bar1" package as a jar. I right click the bar1 package, click "Export" and select JAR. However, bar1's sub-package, "util". Is not selected by default and will not be exported. If I wanted to export bar1's sub-packages, I would need to select them individually. This is a pain if there are a lot of packages. Is there any way to have Eclipse add the "util" sub-package for exporting when I try to export the "bar1" package?

enter image description here

like image 717
Feles Avatar asked Nov 02 '22 20:11

Feles


1 Answers

I think what you have is correct and there is not a lot of automation or easier way beside clicking your way through it to select a specific package and sub-packages. However, I think you can use ant or maven to do this for you which is much automated and easier. Here is how you can select specific package in ant :

<dirset dir="aDirectory">
    <include name="a/package/**"/>
    <exclude name="**/package/to/exclude**"/>
</dirset>
like image 166
grepit Avatar answered Nov 09 '22 10:11

grepit