IFolder.create throws ResourceException (already exists) [message #244631] |
Mon, 18 June 2007 19:12  |
Eclipse User |
|
|
|
Originally posted by: monikakrug.expires-2007-06-30.arcornews.de
IJavaProject javaProject = JavaCore.create(project);
IFolder binDir = project.getFolder("bin");
if (!binDir.exists())
{
binDir.create(false /*force*/, true /*local*/, null /*monitor*/);
}
The line "binDir.create" occasionally (usually in 1 or 2 out of 34
testcases, but sometimes in none) throws this exception:
org.eclipse.core.internal.resources.ResourceException: Resource
/Project03/bin already exists.
I don't get it. I check if it exists and only call create if it doesn't.
There is no other thread running that could be creating the directory
just in the moment between the check and the create call.
What could be causing this?
Monika.
|
|
|
|
Re: IFolder.create throws ResourceException (already exists) [message #244651 is a reply to message #244646] |
Tue, 19 June 2007 06:42   |
Eclipse User |
|
|
|
Originally posted by: monikakrug.expires-2007-06-30.arcornews.de
Daniel Megert schrieb:
> Out of the box (i.e. if not changed by the user) the 'bin' folder is the
> output folder where JDT Core puts its stuff (e.g. class files). This
> folder belongs to JDT Core and they delete, create and modify it. You
> should not mess with that folder unless you really want to run into
> trouble ;-)
So when I create a Java project, does the bin folder get created
automatically? The book I am reading ("Contributing to Eclipse:
Principles, Patterns, and Plug-ins") shows the process of creating a
Java project: creating the project, setting the Java nature, creating
the Java project, adding the JRE container to the classpath - then goes
on with creating the bin folder, adding it to the classpath, creating
the src folder, adding it to the build path. But the book is on Eclipse
2. Has this changed in version 3?
Monika.
|
|
|
Re: IFolder.create throws ResourceException (already exists) [message #244662 is a reply to message #244651] |
Tue, 19 June 2007 07:22   |
Eclipse User |
|
|
|
Monika Krug wrote:
> Daniel Megert schrieb:
>
>> Out of the box (i.e. if not changed by the user) the 'bin' folder is
>> the output folder where JDT Core puts its stuff (e.g. class files).
>> This folder belongs to JDT Core and they delete, create and modify
>> it. You should not mess with that folder unless you really want to
>> run into trouble ;-)
>
>
> So when I create a Java project, does the bin folder get created
> automatically? The book I am reading ("Contributing to Eclipse:
> Principles, Patterns, and Plug-ins") shows the process of creating a
> Java project: creating the project, setting the Java nature, creating
> the Java project, adding the JRE container to the classpath - then
> goes on with creating the bin folder, adding it to the classpath,
> creating the src folder, adding it to the build path. But the book is
> on Eclipse 2. Has this changed in version 3?
I guess it only tries to explain what goes on behind the scenes. If you
want to create a Java project you don't need to create the output
folder(s) yourself. That was always like that. If you do want to create
them you must ensure not to get in conflict with JDT Core.
Dani
>
> Monika.
|
|
|
|
|
|
Re: IFolder.create throws ResourceException (already exists) [message #244732 is a reply to message #244727] |
Wed, 20 June 2007 05:34  |
Eclipse User |
|
|
|
Originally posted by: monikakrug.expires-2007-06-30.arcornews.de
Daniel Megert schrieb:
> Monika Krug wrote:
>
>> Daniel Megert schrieb:
>>
>>> I guess it only tries to explain what goes on behind the scenes. If
>>> you want to create a Java project you don't need to create the output
>>> folder(s) yourself. That was always like that. If you do want to
>>> create them you must ensure not to get in conflict with JDT Core.
>>
>>
>> I looked at my source code again, it actually is like this:
>>
>> IFolder binDir = project.getFolder("bin");
>> if (!binDir.exists())
>> {
>> binDir.create(true /* force */, true /* local */, null);
>> }
>> IPath binPath = binDir.getFullPath();
>> IJavaProject javaProject = JavaCore.create(project);
>> javaProject.setOutputLocation(binPath, null);
>>
>> The IJavaProject is only created after creating the "bin" directory.
>> So the JDT Core should not be concerned with it in the binDir.create
>> line.
>
> Correct.
>
> You are talking about test cases - might it be possible that you reuse
> the same project name for different tests? If so, I assume you delete
> the project and/or folder on tearDown. Make sure that the deletion is
> successful (it can fail sometimes if the OS is still locking some
> files). In JDT we loop until it is successfully deleted. Also note that
> exists() is a handle method i.e. if the workspace model does not contain
> the folder it will return 'false' even if the folder exists in the OS
> and then fails when you try to create it.
Hmm, I often run a test that creates some dozen projects, then delete
all of them manually (inside Eclipse), then run the test again that
creates projects with the same names again. So I guess they could be
still existing on the file system.
I removed the lines that create the bin folder and make it the output
folder (so all of the lines above except for the one that creates the
Java project) and the bin folder gets created anyway and is the
outputfolder, as you said it would be. Thanks for the advice.
Monika.
--
All wars are civil wars, because all men are brothers ... Each one owes
infinitely more to the human race than to the particular country in
which he was born. - Francois Fenelon, theologian and writer (1651-1715)
E-mail address is valid until 4 weeks after the expiration date. Use
@arcor.de instead.
|
|
|
Powered by
FUDForum. Page generated in 0.28177 seconds