Programmatically generate an Eclipse project

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.

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

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?

For the curious, the error I get trying to deserialize the .location file is the following: invalid stream header: 40B18B81

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.

Asked by: Catherine491 | Posted: 28-01-2022

Answer 1

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.

The barebones code to create a project is:

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

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.

Answered by: Tess885 | Posted: 01-03-2022

Answer 2

Use AntEclipse

It can create eclipse projects from ant.

Answered by: Maddie575 | Posted: 01-03-2022

Answer 3

To create java project you can use JavaCore from org.eclipse.jdt.core.JavaCore. As a sourceProject you can use generic project item, which has been suggested by @James Van Huis

IJavaProject javaSourceProject = JavaCore.create(sourceProject);

Answered by: Leonardo885 | Posted: 01-03-2022

Similar questions

java - Is it possible to programmatically generate JUnit test cases and suites?

I have to write a very large test suite for a complex set of business rules that are currently captured in several tabular forms (e.g., if parameters X Y Z are such and such, the value should be between V1 and V2). Each rule has a name and its own semantics. My end goal is to have a test suite, organized into sub test suites, with a test case to each rule. One option is to actually hard code all these rules...

java - How to programmatically generate .class files?

I would like to write a compiler for a toy-language for Java. I would like to generate runnable .class files. I was wondering what is the best library or tool available for doing this? I know I could learn the binary format for all the instructions and build my own constant pool etc, but that seems like work that ought to have been already done: no point reinventing the wheel, right? Searching online I've found two...

How can I programmatically find the path of JNLP file? I am using Java Web Start to generate the JNLP file

How can I programmatically find the path of JNLP file?I am using Java Web Start to generate the JNLP file. I know that manually you can find the JNLP file in the Java Cache Viewer in Resources with the name launch.jnlp, but I really need to know if there exists a Java class that can programmatically find the jnlp file by searching the in-memory cache.

java - Trouble during generate XLS programmatically

This code i have deployed on server side to convert a rep file (BO File )to xls file using macro of XLs.I invoked the macro through this jsp call and Macro convert .rep file to xls file . . When invoke the jsp from client side on server system donot open xls sheet , but when i try to run same code as a standalone java code it work. Here i hjave attached a sample code.Could please help me. &lt;%@ page impor...

java - How can I programmatically generate keypress events?

This question already has an answer here:

java - Spring generate oauth2 access token programmatically

I have a Web Sesrvices protected by spring security OAuth2 and I can get access token using http request oauth/token... I have another requirement: to generate the access token in java and authenticate the user using: SecurityContextHolder.getContext().setAuthentication(oauthToken); in order to have access to web services via this token. This is my curent code: UserDetail...

java - How to generate array of text labels for date interval chart programmatically

I'm trying to implement a chart to show some interval based data. For the orizontal axis labels I need an array that contains all text labels. The problem is that: I have to generate this array programmatically according the passed GregorianCalendar startDate, GregorianCalendar endDate (and months havent all the same days number) eg assuming I need a chart from 7th July

iphone - How to generate .p12 using java programmatically?

Am developing a web application in java using Struts2 framework. From web application i have an option to send push notification. So I developed REST api's that has been used in Android &amp; iPhone. No problem regarding android because to send push notification we just need to store the GCM api key. But problem is in iPhone. In iPhone from apple w...

Generate XSD from XML programmatically in Java

I'm looking for a leightweight library that allows me to genereate an XSD from XML in Java (no commandline tool). I know that it is not a clean way to generate it, but in this case I need to do it. Also the XML is very simple in terms of structure. I already looked into Trang, but there is no API documentation except how to call it from command line. Also I checked out xsd-gen, but the issue with that lib...

java - What are the ways to programmatically generate Material Design color sets?

I am trying to create a colour palette of Material Design that changing the lightness / luminosity by percentage with arbitrary color hex. When it comes to the implementation, I have found that there are some color hex I cannot generate and shows Color Unknown Exception. Would you please tell me what are the alternatives or technical precautions to generate this set of colours?

java - How do I programmatically inspect a HTML document

I have a database full of small HTML documents and I need to programmatically insert several into, say, a PDF document with iText or a Word document with Aspose.Words. I need to preserve any formatting within the HTML documents (within reason, honouring &lt;b&gt; tags is a must, CSS like &lt;span style="blah"&gt; is a nice-to-have). Both iText and Aspose work (roughly) along the lines: ...

How do I programmatically determine operating system in Java?

I would like to determine the operating system of the host that my Java program is running programmatically (for example: I would like to be able to load different properties based on whether I am on a Windows or Unix platform). What is the safest way to do this with 100% reliability?

eclipse - Can you register an ActiveX dll in Java programmatically?

I have a third-party ActiveX dll, and I'd like to register it programmatically at run time, if possible. Can this be done in Java? The application I'm working with is an Eclipse application on Windows XP.

Convert Word doc to HTML programmatically in Java

I need to convert a Word document into HTML file(s) in Java. The function will take input an word document and the output will be html file(s) based on the number of pages the word document has i.e. if the word document has 3 pages then there will be 3 html files generated having the required page break. I searched for open source/non-commercial APIs which can convert doc to html but for no result. Anybody who have...

java - How can I programmatically test an HTTP connection?

Using Java, how can I test that a URL is contactable, and returns a valid response?

java - How to programmatically add portlet to the JBoss Portal dashboard

Closed. This question does not meet Stack Overflow guid...

java - Programmatically marking an Oracle BPEL task complete

I am using Oracle BPEL Process manager and have a task assigned to a group of users. I try to mark it approved using Java class This works if the task is assigned to an individual user, but if the task is assigned to a group of users, I get an error message about the task not being acquired. If I acquire the task using

java - How to Send Encrypted Emails Programmatically (from an automated process)

I have a process that runs on a UNIX (Solaris) server that runs nightly and needs to be able to send out encrypted emails. I only need the "encryption" portion, NOT the digital signature / self-repudiation part of PKI. I use MS Outlook in a corporate setting and I am assuming that when a user clicks "Publish to GAL..." under Tools -> Options -> Security, this will publish their PUBLIC KEY to the Global Addr...

java - Need a way to check status of Windows service programmatically

Here is the situation: I have been called upon to work with InstallAnywhere 8, a Java-based installer IDE, of sorts, that allows starting and stopping of windows services, but has no built-in method to query their states. Fortunately, it allows you to create custom actions in Java which can be called at any time during the installation process (by way of what I consider to be a rather convoluted API). I ...

java - Programmatically transcode MPEG-2 videos

I need to be able to programmatically transcode mpeg-2 files to .mp4, .mp3, .wmv, .rm (optional), and .flv (optional), and hopefully generate a thumbnail as well. I found the Java Media Framework, but it frankly looks pretty crappy. This will be running a Linux server, so I could shell out to ffmpeg using Commons Exec - does ffmpeg do everything I need to do? FFmpeg seems pretty daunting, which is why I'm having trouble fi...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)