Creting EJB project in JUnit test [message #206243] |
Wed, 02 January 2008 08:32 |
Eclipse User |
|
|
|
Originally posted by: k.mitov.xxx.xxx
Hi all,
I am trying to create an ejb project in a JUnit test.
This are the methods that I use:
private static void createProject() throws CoreException,
InterruptedException {
final IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject("CreateModelTestProject ");
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.create(monitor);
project.open(monitor);
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 2];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[newNatures.length - 2] = JavaCore.NATURE_ID;
newNatures[newNatures.length - 1] = FacetedProjectNature.NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, monitor);
}
}, new NullProgressMonitor());
Job workspaceJob = new WorkspaceJob("Create Facets...") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws
CoreException {
IFacetedProject fProject = ProjectFacetsManager.create(project);
Set<Action> actions = new HashSet<Action>();
actions.add(setupJavaInstallAction());
actions.add(setupEjbInstallAction());
fProject.modify(actions, monitor);
facetedProject = fProject;
return Status.OK_STATUS;
}
};
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new
NullProgressMonitor());
workspaceJob.schedule();
workspaceJob.join();
}
public static IFacetedProject.Action setupEjbInstallAction() {
IDataModel ejbFacetInstallDataModel =
DataModelFactory.createDataModel(new
EjbFacetProjectCreationDataModelProvider());
ejbFacetInstallDataModel.setProperty(IEjbFacetInstallDataMod elProperties.CONFIG_FOLDER,
"ejbModule");
IProjectFacetVersion webfacetversion =
ProjectFacetsManager.getProjectFacet("jst.ejb").getVersion( "3.0");
IFacetedProject.Action action = new
IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL,
webfacetversion, ejbFacetInstallDataModel);
return action;
}
public static IFacetedProject.Action setupJavaInstallAction() {
IProjectFacetVersion javafacetversion = ProjectFacetsManager.
getProjectFacet("jst.java"). getVersion("5.0");
IDataModel javaFacetInstallDataModel = DataModelFactory
.createDataModel(new JavaFacetInstallDataModelProvider());
javaFacetInstallDataModel.setProperty(IJavaFacetInstallDataM odelProperties.SOURCE_FOLDER_NAME,
"ejbModule");
IFacetedProject.Action action = new
IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL,
javafacetversion, javaFacetInstallDataModel);
return action;
}
The problem is that after I create the project the "ejbModule" directory
is not a source directory but is a package.
I suppose that the JavaFacetInstallDataModelProvider does not correctly
create the source folder despite the fact the i have specified the
SOURCE_FOLDER_NAME property.
Can anyone help me with this problem?
Best Regards,
Kiril
|
|
|
|
Re: Creting EJB project in JUnit test [message #206274 is a reply to message #206251] |
Wed, 02 January 2008 09:39 |
Eclipse User |
|
|
|
Originally posted by: k.mitov.xxx.xxx
I solved it.
You MUST not have a java nature set up in you projects before installing
the java facet. If you have a java nature then a cecrtain piece of code in
JavaFacetInstallDelegate is missed and the project is not configured
correctly.
The code inside the !jproject.exists() block is not executed if you
already have a java nature installed in you project.
final IPath pjpath = project.getFullPath();
IJavaProject jproject = null;
if( project.exists()){
jproject = JavaCore.create(project);
}
if( !jproject.exists()){
// configuration here
}
Best Regards,
Kiril
|
|
|
Powered by
FUDForum. Page generated in 0.03118 seconds