繁体   English   中英

未在Eclipse中创建项目

[英]Project is not created in Eclipse

我正在尝试使用处理程序类将插件项目作为应用程序运行:

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window =
            HandlerUtil.getActiveWorkbenchWindowChecked(event);
    MessageDialog.openInformation(
        window.getShell(), "MenuEclipseArticle Plug-in",
        "Hello, Eclipse world");
    CreateProject create=new CreateProject();
    IPath  projectLocation =  new Path("C:/Users/monika.sharma/Desktop/software");
    String projectName = "myProject1234";
    create.createProject(projectLocation, projectName);

    return null;
}

我创建了一个createProject Java类来创建带有srcbin文件夹的项目。

public class CreateProject {

    static boolean createAtExternalLocation = false;
     static IPath projectLocation=null;
     private IProject project;
     private IJavaProject javaProject;

    public void createProject(IPath projectLocation,String projectName)
    {
        IProgressMonitor progressMonitor = new NullProgressMonitor();
    IProject project =ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    IProjectDescription description =ResourcesPlugin.getWorkspace().newProjectDescription(project .getName());
    description.setLocation(projectLocation);

    try {
        project.create(description, progressMonitor);
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        project.open(progressMonitor);
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     try {
        setJavaNature();
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     // Add JRE
     try {
        addDefaultJRE(progressMonitor);
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     // Create the bin folder
     try {
        createBinFolder();
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     // Create a source folder
     try {
        IPackageFragmentRoot src = createSourceFolder("src");
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }
    public void setJavaNature() throws CoreException {
         // Get the description of the project
         IProjectDescription description = project.getDescription();
         // Change the description with NATURE_ID of JavaCore
         description.setNatureIds(new String[] {JavaCore.NATURE_ID});
         // Set the description back to the project
         project.setDescription(
             description, null);
    }
    public void addDefaultJRE(IProgressMonitor progressMonitor) throws JavaModelException {
         // Create an empty class path entry array for the project
         javaProject.setRawClasspath(
             new IClasspathEntry[0], progressMonitor);
         // Get it - the old entries
         IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
         // Increase 1 for the size of the new entry array.
         IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
         // Copy the old entries to new entry array.
         System.arraycopy(
             oldEntries, 0, newEntries, 0, oldEntries.length);
         // Set the new element to the default JRE of the system.
         newEntries[oldEntries.length] = JavaRuntime.getDefaultJREContainerEntry();
         // Set back entry paths to the project
         javaProject.setRawClasspath(
             newEntries, progressMonitor);
    }
    public IFolder createBinFolder() throws CoreException {
         // Get the folder with the name bin
         IFolder binFolder = project.getFolder("bin");
         // Create this folder. if the first parameter is false, it does not
         // forced to override the folder
         binFolder.create(
             false, true, null);
         // Get the path of the bin folder
         IPath outputLocation = binFolder.getFullPath();
         // Set that path as the output location of the project
         javaProject.setOutputLocation(
             outputLocation, null);
         return binFolder;
    }
    public IPackageFragmentRoot createSourceFolder(String srcName) throws CoreException {
         // Get the folder with srcName name. It may be not exist
         IFolder folder = project.getFolder(srcName);
         // Create a real folder. In the case you want to force override the
         // folder,
         // set the first parameter as true
         folder.create(
             false, true, null);
         // Get the source folder as root package
         IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
         // Do the samething on the addDefaultJRE method
         IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
         IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
         System.arraycopy(
             oldEntries, 0, newEntries, 0, oldEntries.length);
         // Add a new source folder as a new entry for class paths
         newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath());
         // Set back entry paths to the project
         javaProject.setRawClasspath(
             newEntries, null);
         return root;
    }

当我使用“作为Eclipse应用程序运行”运行MANIFEST.MF文件时,仅打开Eclipse,但未创建项目。

“作为Eclipse应用程序运行”只是启动一个包含您的插件的新Eclipse。 新的Eclipse使用一个单独的工作区。 在“运行>运行配置”对话框的“ Eclipse应用程序”部分中查找详细信息。

这不会调用您的处理程序代码。 处理程序仅在从菜单项或工具栏按钮之类调用时才运行。 必须使用org.eclipse.ui.handlers扩展点声明该处理程序。 有关处理程序的更多详细信息,请阅读以下内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM