Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Exclude Certain Packages From Export (Java)(How to exclude certain packages while exporting a Java project (specifically to an executable .jar))
Exclude Certain Packages From Export (Java) [message #631575] Fri, 08 October 2010 04:41 Go to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Hello, world!

I just started using Eclipse with Java yesterday, and everything in going nicely so far.

I'd like to export my project to an executable .jar, but I don't want to include my jUnit tests. How can I exclude them from the export? I tried to go Project > Properties > Build Path > Export tab, but I can't check/un-check the packages I want/don't want.

Thanks in advance!
Re: Exclude Certain Packages From Export (Java) [message #631602 is a reply to message #631575] Fri, 08 October 2010 07:43 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Jonah Bron wrote:
> Hello, world!
>
> I just started using Eclipse with Java yesterday, and everything in
> going nicely so far.
>
> I'd like to export my project to an executable .jar, but I don't want
> to include my jUnit tests.
Simply uncheck when doing the JAR Export. If you plan to repeat the
export you can store it in a JAR description.

Dani
> How can I exclude them from the export? I tried to go Project >
> Properties > Build Path > Export tab, but I can't check/un-check the
> packages I want/don't want.
>
> Thanks in advance!
Re: Exclude Certain Packages From Export (Java) [message #631762 is a reply to message #631575] Fri, 08 October 2010 15:56 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Quote:
Simply uncheck when doing the JAR Export. If you plan to repeat the
export you can store it in a JAR description.

Dani


Thanks for the reply. What I was trying to say was, I can't uncheck any source folders. They're already unchecked. Here's a screenshot to show you what I mean.

http://s1046.photobucket.com/albums/b465/jonahbron/?action=v iew&current=screenshot.png

Thanks
Re: Exclude Certain Packages From Export (Java) [message #631771 is a reply to message #631762] Fri, 08 October 2010 16:32 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2010.10.08 9:56, Jonah Bron wrote:
> Thanks for the reply. What I was trying to say was, I can't uncheck any
> source folders. They're already unchecked. Here's a screenshot to show
> you what I mean.
>
> http://s1046.photobucket.com/albums/b465/jonahbron/?action=v iew&current=screenshot.png
>
>
> Thanks

Jonah,

You don't want to "uncheck" anything in Build Path (per your illustration).

To create a JAR, you right-click on the project and choose Export... (as
you started to do). But, when you reach the JAR Export dialog, you
uncheck what is probably your test subdirectory.*

If you like, peruse this discussion here:

http://www.javahotchocolate.com/tutorials/jars.html


* Now, if you didn't put your JUnit tests under a separate Source
Folder, parallel to src, then you should do that (it's a "best
practice") and that might be why you find it impossible to exclude them.

Come back if this isn't helpful,

Russ Bateman
Re: Exclude Certain Packages From Export (Java) [message #631783 is a reply to message #631575] Fri, 08 October 2010 17:54 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
When exporting a .JAR file, I do see the ability to exclude files/directories. But in this case, I'm exporting a runnable .Jar file, and it gives me no such option.

Quote:
Now, if you didn't put your JUnit tests under a separate Source
Folder, parallel to src, then you should do that (it's a "best
practice")

If what I have setup now is not best practice, please tell me how to change it to best practice. This is the first time I've worked with Java; I have pretty extensive experience with PHP.
Re: Exclude Certain Packages From Export (Java) [message #631950 is a reply to message #631575] Mon, 11 October 2010 00:31 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Bump?
Re: Exclude Certain Packages From Export (Java) [message #631955 is a reply to message #631950] Mon, 11 October 2010 01:41 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2010.10.10 18:31, Jonah Bron wrote:
> Bump?

(Don't bump in this forum. Your question will always be answered as soon
as someone sees it who can answer it.)

Here's how to set up JUnit tests.

1) Right-click the project and choose New -> Source Folder. Name it "test".

2) Right-click test, then choose New -> Package. Name the package the
same as the package under src folder that contains the code your JUnit
class will test.

3) Create your JUnit test class under this package. If you've already
created a JUnit test under src folder, open both src and test, then drag
the JUnit test from under src to under test.
Re: Exclude Certain Packages From Export (Java) [message #631957 is a reply to message #631575] Mon, 11 October 2010 02:21 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Quote:
(Don't bump in this forum. Your question will always be answered as soon
as someone sees it who can answer it.)

Okay, sorry.

I followed your instructions. I now have:

src/
___packagename [package] /
______[code files]
test/
___packagename [package] /
______[test files]

But I still haven't found a way to exclude the jUnit test files from the runnable jar export. Until this problem is solved, I can just do it manually from the terminal. But, this really should work. Any ideas?

Thanks
Re: Exclude Certain Packages From Export (Java) [message #631999 is a reply to message #631957] Mon, 11 October 2010 07:19 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Jonah Bron wrote:
> Quote:
>> (Don't bump in this forum. Your question will always be answered as soon
>> as someone sees it who can answer it.)
>
> Okay, sorry.
>
> I followed your instructions. I now have:
>
> src/
> ___packagename [package] /
> ______[code files]
> test/
> ___packagename [package] /
> ______[test files]
>
> But I still haven't found a way to exclude the jUnit test files from
> the runnable jar export. Until this problem is solved, I can just do
> it manually from the terminal. But, this really should work. Any ideas?
Use File > Export... > JAR file

Dani
>
> Thanks
Re: Exclude Certain Packages From Export (Java) [message #632099 is a reply to message #631575] Mon, 11 October 2010 14:57 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Thanks Dani, but I'm trying to export the runnable jar without jUnit or my test classes.
Re: Exclude Certain Packages From Export (Java) [message #632107 is a reply to message #632099] Mon, 11 October 2010 15:00 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Jonah Bron wrote:
> Thanks Dani, but I'm trying to export the runnable jar without jUnit
> or my test classes.
Right, and as you notice this doesn't work unless you split the tests
into a separate project or use the way I suggested.

Dani
Re: Exclude Certain Packages From Export (Java) [message #632108 is a reply to message #631957] Mon, 11 October 2010 15:05 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2010.10.10 20:21, Jonah Bron wrote:
> Quote:
>> (Don't bump in this forum. Your question will always be answered as soon
>> as someone sees it who can answer it.)
>
> Okay, sorry.
>
> I followed your instructions. I now have:
>
> src/
> ___packagename [package] /
> ______[code files]
> test/
> ___packagename [package] /
> ______[test files]
>
> But I still haven't found a way to exclude the jUnit test files from the
> runnable jar export. Until this problem is solved, I can just do it
> manually from the terminal. But, this really should work. Any ideas?
>
> Thanks


Please peruse this example for a step-by-step:

http://www.javahotchocolate.com/tutorials/jars.html#jarexamp le
Re: Exclude Certain Packages From Export (Java) [message #632115 is a reply to message #631575] Mon, 11 October 2010 15:48 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Yes, I figured out how to keep the test code out of a normal .jar export. Are you saying that the .jar export and the runnable .jar export are the same thing? Thanks for your help so far...

Edit: this export option:
http://i1046.photobucket.com/albums/b465/jonahbron/Screenshot-Export.png

[Updated on: Mon, 11 October 2010 15:52]

Report message to a moderator

Re: Exclude Certain Packages From Export (Java) [message #632122 is a reply to message #632115] Mon, 11 October 2010 15:56 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2010.10.11 9:48, Jonah Bron wrote:
> Yes, I figured out how to keep the test code out of a normal .jar
> export. Are you saying that the .jar export and the runnable .jar
> export are the same thing? Thanks for your help so far...

The distinction between the two is that the runnable JAR has a class
containing a main() method.

If you wish to create a JAR containing your JUnit test code that is
runnable, there is a bit more work to it, see note under
http://www.javahotchocolate.com/tutorials/jars.html#runnable jar
Re: Exclude Certain Packages From Export (Java) [message #632137 is a reply to message #631575] Mon, 11 October 2010 17:15 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Yes. My program has a main() method. What I want to do is to make a distribution runnable .jar without the test code in it. Thanks.
Re: Exclude Certain Packages From Export (Java) [message #633133 is a reply to message #632137] Fri, 15 October 2010 13:13 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
On 10/11/10 1:15 PM, Jonah Bron wrote:
> Yes. My program has a main() method. What I want to do is to make a
> distribution runnable .jar without the test code in it. Thanks.

What I think Dani and Russell are trying to tell you is that you need to
do Export > JAR and then specify a manifest file that makes it runnable
(Google "runnable jar manifest" for details on the contents of the
manifest file).
It might be easiest to use the Runnnable JAR export wizard to generate
the JAR with manifest and then copy it's manifest file into your project
so you can use it for the "regular" JAR export where you exclude test code.

Hope this helps,
Eric
Re: Exclude Certain Packages From Export (Java) [message #633217 is a reply to message #631575] Fri, 15 October 2010 17:00 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Great! That works, I suppose I didn't understand. I wonder why the export runnable jar doesn't give you the option to remove selected directories/files. I copied the manifest into my project directory, so now I just select "Use existing manifest from workspace" when exporting a normal jar.

Thanks a lot!
Re: Exclude Certain Packages From Export (Java) [message #633280 is a reply to message #631575] Sat, 16 October 2010 00:12 Go to previous messageGo to next message
John Marston is currently offline John MarstonFriend
Messages: 1
Registered: October 2010
Junior Member
Wow, I finally figured what was normal .jar
> export doing differently. Thanks for all the info, I am new to programming and learning something new everyday.
Re: Exclude Certain Packages From Export (Java) [message #1851730 is a reply to message #633280] Thu, 14 April 2022 03:59 Go to previous message
Taro App is currently offline Taro AppFriend
Messages: 4
Registered: July 2009
Junior Member
I had the same issue, and here's the better solution. You don't have to use normal jar export, and you can fine control which files to include/exclude. See this:

https://stackoverflow.com/a/71866303/1837675
Previous Topic:Edit/manage .dita/.ditamap
Next Topic:when install new Software ProvisionException occurred
Goto Forum:
  


Current Time: Fri Mar 29 01:31:06 GMT 2024

Powered by FUDForum. Page generated in 0.04701 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top