以编程方式生成Eclipse项目 [英] Programmatically generate an Eclipse project

查看:101
本文介绍了以编程方式生成Eclipse项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用eclipse来处理最初独立于eclipse创建的应用程序。因此,应用程序的目录结构确实不是eclipse友好的。

I use eclipse to work on an application which was originally created independently of eclipse. As such, the application's directory structure is decidedly not eclipse-friendly.

我想以编程方式为应用程序生成一个项目。 .project .classpath 文件很容易弄清楚,我了解到项目存储在< workspace> /。metadata / .plugins / org.eclipse.core.resources / .projects

I want to programmatically generate a project for the application. The .project and .classpath files are easy enough to figure out, and I've learned that projects are stored in the workspace under <workspace>/.metadata/.plugins/org.eclipse.core.resources/.projects

不幸的是,这里的一些文件(特别是 .location )似乎是以某种二进制格式编码的。在一个预感中,我试图使用 ObjectInputStream 反序列化它 - 没有骰子。所以它似乎不是一个序列化的java对象。

Unfortunately, some of the files under here (particularly .location) seem to be encoded in some kind of binary format. On a hunch I tried to deserialize it using ObjectInputStream - no dice. So it doesn't appear to be a serialized java object.

我的问题是:有没有办法自动生成这些文件?

My question is: is there a way to generate these files automatically?

对于好奇,我试图反序列化 .location 文件的错误如下:

For the curious, the error I get trying to deserialize the .location file is the following:

java.io.StreamCorruptedException:java.io.StreamCorruptedException:invalid stream header:40B18B81

更新:我的目标是使用命令行脚本或程序替换新的Java Project向导。原因是有关应用程序实际上是一个非常大的J2EE / weblogic应用程序,我喜欢将其分解成大量(近20个)子项目集合。复杂的事情,我们使用clearcase为SCM,并为每个版本创建一个新的分支。这意味着我需要为我创建的每个开发视图(分支)重新创建这些项目。

Update: My goal here is to be able to replace the New Java Project wizard with a command-line script or program. The reason is the application in question is actually a very large J2EE/weblogic application, which I like to break down into a largish (nearly 20) collection of subprojects. Complicating matters, we use clearcase for SCM and create a new branch for every release. This means I need to recreate these projects for every development view (branch) I create. This happens often enough to automate.

推荐答案

您应该能够通过编写一个小的Eclipse插件来完成此任务。您甚至可以将其扩展为无头RCP应用程序,并传递您需要的命令行参数。

You should be able to accomplish this by writing a small Eclipse plugin. You could even extend it out to being a "headless" RCP app, and pass in the command line arguments you need.

创建项目的准系统代码是: / p>

The barebones code to create a project is:

IProgressMonitor progressMonitor = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("DesiredProjectName");
project.create(progressMonitor);
project.open(progressMonitor);

只需查看导入项目向导的eclipse代码,让您更好地了解哪里一起去吧。

Just take a look at the eclipse code for the Import Project wizard to give you a better idea of where to go with it.

这篇关于以编程方式生成Eclipse项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆