views:

84

answers:

4

Hello,

I would like to generate Eclipse Java Project with my Java program. When I click a button: it will generate an eclipse project with the parameters I specified (source path, library, ...)

My questions are:

  • is there a way to do that ? and how ? (api).

  • it is possible to generate Net-beans project too ?

Best regards,

Florent

+4  A: 

Maven enables this and many more things around creating, bulding, testing and developing Java projects.

Create a Java project from command line. Then, using Maven create NetBeans, Eclipse or IntelliJ IDEA specific project files. Or even easier, just import already created Maven project directly from these IDEs.

Boris Pavlović
I agree, this is the best way to go, although I am somewhat tempted to hack together a custom solution :-) +1
seanizer
I search on the web and see jdt api that permit to create eclipse project. But if i understood it is not possible to use it without eclipse that's right ?
Delildor
Yes Maven it's a good solution, but i think it's not possible for me to implement it. If i have understood your proposition, i have too create a maven project and then generate ide project with it. There is no simple way to generate eclipse project with a specific api ?
Delildor
Go on Delildor. You'll learn a lot going that path.
Boris Pavlović
+3  A: 

Create Java Project in Eclipse first. Then look into directory created. You should find there two files: .project and .classpath. These are the files you should create in your app to get what you want.

Piotr Maj
I like this, because I am a dirty hacker myself sometimes :-) +1
seanizer
So, you create this two files and it's ready to use with eclipse ?
Delildor
Did you have some example of a function that permit to create this two files ?
Delildor
Just create a basic Eclipse project and look into the files. Important in `.project` is the java nature and the project name. Important in the `.classpath` is that you define all the source folders and the output folder + the default JRE library container. Since both files are XML, using an XML Library like JDOM could be appropriate.
Johannes Wachter
you need to create the whole structure of the project of course with sources, target dirs, etc. Please create eclipse project and analyze deeply what eclipse generated for you. Then use the files as a templates in your app.
Piotr Maj
thank you, for your answer. i will try.
Delildor
+1  A: 

Also for eclipse available M2Eclipse plugin to provide some Maven feature from Eclipse IDE. http://m2eclipse.sonatype.org/

kvieserc
While I agree that this is the best way to go, the OP has not mentioned using maven and your answer does not elaborate enough on what good this would do him.
seanizer
Hey seanizer, why not offer your own solution instead of just commenting on everyone else's?
duffymo
+1  A: 

While Maven is the way to go in the long term, the best way to start a project in Eclipse is:

  1. Hit Ctrl+N and choose Java project
  2. Fill in the project name fields
  3. Copy your files from wherever they are to the newly created project (ensuring to preserve package hierarchy)
  4. Refresh project from File menu
  5. Create a Run / Debug profile to run your app.

It should be fairly simple to get up and running this way.

The reason people recommend Maven is because Eclipse is an IDE. It's great for development but its no good for resolving external dependencies or for command line / automated builds. Maven is an IDE neutral way of building and becomes essential the more dependencies a project pulls in.

Unfortunately Eclipse integration with Maven is pretty clumsy and can be summarized with these very broad steps:

  1. Install Eclipse Helios
  2. Install m2eclipse from the Help | Eclipse Marketplace
  3. Mess around with eclipse.ini to make Eclipse start from a JDK.
  4. Configure m2eclipse to use any existing Maven local repository
  5. Hit Ctrl+N and create a new Maven project and skip archetype selection
  6. Copy all the source files from the old project into the new ensuring to use Maven's conventions for file locations. (e.g. source goes in src/main/java)
  7. Create a Run / Debug maven target to clean / install the app

I say broad steps because there are a lot of gotchas. For example if the source is Java 5+ you might have to tweak the pom to set the compiler level. Best to get Eclipse working and then worry about Maven.

Netbeans has vastly better out of the box support for Maven although IMO Eclipse is still the better IDE for other reasons.

locka