Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » create a project from java file
create a project from java file [message #298200] Thu, 26 January 2006 10:32 Go to next message
Eclipse UserFriend
Originally posted by: maclacla.inwind.it

Hi all,
Can I create a new project with the eclipse API in a java program?
Before I have created the directory in my workspace and after that I need
to create the project in order to show the file in the workbench.
Can someone explane that or send me some code?
Please help me.

Thanks in advance.

max
Re: create a project from java file [message #298207 is a reply to message #298200] Thu, 26 January 2006 10:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------040404000301000105080400
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Max,

Maybe this will help:

public static IContainer findOrCreateContainer
(IPath path, boolean forceRefresh, IPath localLocation,
IProgressMonitor progressMonitor) throws CoreException
{
String projectName = path.segment(0);
IProjectDescription projectDescription =
ResourcesPlugin.getWorkspace().newProjectDescription(project Name);
projectDescription.setLocation(localLocation);
return findOrCreateContainer(path, forceRefresh,
projectDescription, progressMonitor);
}

public static IContainer findOrCreateContainer
(IPath path, boolean forceRefresh, IProjectDescription
projectDescription, IProgressMonitor progressMonitor) throws
CoreException
{
try
{
String projectName = path.segment(0);
progressMonitor.beginTask("", path.segmentCount() + 3);

progressMonitor.subTask(CodeGenPlugin.getPlugin().getString( "_UI_ExaminingProject_message",
new Object [] { projectName }));
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project =
workspace.getRoot().getProject(path.segment(0));

if (forceRefresh)
{
project.refreshLocal(IResource.DEPTH_INFINITE, new
SubProgressMonitor(progressMonitor, 1));
}
else
{
progressMonitor.worked(1);
}

if (!project.exists())
{
project.create(projectDescription, new
SubProgressMonitor(progressMonitor, 1));
project.open(new SubProgressMonitor(progressMonitor, 1));
}
else
{
project.open(new SubProgressMonitor(progressMonitor, 2));
}

IContainer container = project;
for (int i = 1, length = path.segmentCount(); i < length; ++ i)
{
IFolder folder = container.getFolder(new
Path(path.segment(i)));
if (!folder.exists())
{
folder.create(false, true, new
SubProgressMonitor(progressMonitor, 1));
}
else
{
progressMonitor.worked(1);
}

container = folder;
}

return container;
}
finally
{
progressMonitor.done();
}
}


max wrote:

> Hi all,
> Can I create a new project with the eclipse API in a java program?
> Before I have created the directory in my workspace and after that I
> need to create the project in order to show the file in the workbench.
> Can someone explane that or send me some code?
> Please help me.
>
> Thanks in advance.
>
> max
>


--------------040404000301000105080400
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Max,<br>
<br>
Maybe this will help:<br>
<br>
<blockquote><small>
Re: create a project from java file [message #298256 is a reply to message #298207] Fri, 27 January 2006 04:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: maclacla.inwind.it

Hi Ed, thanks for your answer.
I create this class to call your method but when it call

IProjectDescription projectDescription =
ResourcesPlugin.getWorkspace().newProjectDescription(project Name);

catch the exception IllegalStartException workspace is closed.

Why? where I wrong?
Sorry, these are maybe stupid questions, but i am a new user of Eclipse
and i dont know so much of it.

Thanks again.

Max

public createProgect()
{
IPath path = new Path("work");
IProgressMonitor progressMonitor = new NullProgressMonitor();
try
{
IContainer myContainer = findOrCreateContainer(path, true,
path, progressMonitor);
}
catch (CoreException e)
{
e.printStackTrace();
}

}
Re: create a project from java file [message #298262 is a reply to message #298256] Fri, 27 January 2006 06:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Max,

It sounds like you aren't really running in an initialized Eclipse
environment. I'd need to understand more of your runtime context since
the workspace is not normally closed. How are you running your
application? (You'll maybe need to learn about how to run a headless
Eclipse; try searching for that.)


max wrote:

> Hi Ed, thanks for your answer.
> I create this class to call your method but when it call
>
> IProjectDescription projectDescription =
> ResourcesPlugin.getWorkspace().newProjectDescription(project Name);
> catch the exception IllegalStartException workspace is closed.
>
> Why? where I wrong?
> Sorry, these are maybe stupid questions, but i am a new user of
> Eclipse and i dont know so much of it.
>
> Thanks again.
>
> Max
>
> public createProgect() {
> IPath path = new Path("work"); IProgressMonitor
> progressMonitor = new NullProgressMonitor();
> try {
> IContainer myContainer = findOrCreateContainer(path, true,
> path, progressMonitor);
> }
> catch (CoreException e)
> {
> e.printStackTrace();
> }
>
> }
>
Re: create a project from java file [message #298301 is a reply to message #298262] Sat, 28 January 2006 04:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: maclacla.inwind.it

Ed,
the scenario is this: we have to use some plugins created by our friends.
This plugins are editors to design UML diagrams.

For example I have this file : MyDiagram.drd (it's something like UML use
case diagram).

I'd need to create a Java program that allow to execute (and then load in
the workspace) this file. When my Java program start, Eclipse is
closed...so I'd need to open Eclipse and load the diagram.

Any help is welcome.

Best regards.

Max


Ed Merks wrote:

> Max,

> It sounds like you aren't really running in an initialized Eclipse
> environment. I'd need to understand more of your runtime context since
> the workspace is not normally closed. How are you running your
> application? (You'll maybe need to learn about how to run a headless
> Eclipse; try searching for that.)


> max wrote:

>> Hi Ed, thanks for your answer.
>> I create this class to call your method but when it call
>>
>> IProjectDescription projectDescription =
>> ResourcesPlugin.getWorkspace().newProjectDescription(project Name);
>> catch the exception IllegalStartException workspace is closed.
>>
>> Why? where I wrong?
>> Sorry, these are maybe stupid questions, but i am a new user of
>> Eclipse and i dont know so much of it.
>>
>> Thanks again.
>>
>> Max
>>
>> public createProgect() {
>> IPath path = new Path("work"); IProgressMonitor
>> progressMonitor = new NullProgressMonitor();
>> try {
>> IContainer myContainer = findOrCreateContainer(path, true,
>> path, progressMonitor);
>> }
>> catch (CoreException e)
>> {
>> e.printStackTrace();
>> }
>>
>> }
>>
Re: create a project from java file [message #298302 is a reply to message #298301] Sat, 28 January 2006 11:07 Go to previous message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

The only time you get Workspace Closed is because you're trying to fire Eclipse-internals from a public static void main() method, or an application launched by right-clicking on it in Eclipse and doing 'Run as ... Java application'. You can *only* use the Eclipse internals if you're developing a bona-fine plugin and launching it via a 'Runtime workspace'.

Running a Java application from within Eclipse does *not* give you access to Eclipse's internals. The only way you get access to Eclipse's internals is by running as a plug-in and hosted within the Eclipse environment directly. My guess is that what you should do is create a plugin, then hook it up to some kind of Action, then launch a runtime workspace to test your plugin. When you're happy your plugin works, you can install it into your main Eclipse workspace to use for the future.

Alex.
Previous Topic:Enabling and disabling Toolbar Item that represents an action
Next Topic:Problems with custom MarkerResolutionGenerator
Goto Forum:
  


Current Time: Sun May 11 20:40:02 EDT 2025

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

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

Back to the top