prime
prime

Reputation: 799

Create an Eclipse Java project in command line

I'm trying to automate the creation of an Eclipse Java project.

I need a way to do this using the command line.

I found many articles for this for CDT, but not for the java one.

Is there a way to do that with Java IDE?

Upvotes: 1

Views: 1440

Answers (1)

el-teedee
el-teedee

Reputation: 1341

Principles of my solution:

  • get templates of .project and .classpath files from existing projects
  • in a Shell script, use and customize this template to create new Project required files
  • in Eclipse, import filesystem folder as a Project (now possible due to created files)

Below is only the relevant part/end of the script, where .project file is created.
Note: I did not need a .classpath file in my case, thus only importing a Project, not Java Project.

# name: the local Eclipse Folder name I give as script arg
# Create Eclipse .project
projectFile="${name}/.project" ;

# below EOF's content comes from an existing real .project file
echo $( cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
  <name>${name}</name>
  <comment></comment>
  <projects></projects>
  <buildSpec></buildSpec>
  <natures></natures>
</projectDescription>
EOF
) > ${projectFile};
echo "✓ ${projectFile} created" ;

# Create Eclipse .classpath if needed (in case of Java project, not needed for default Project)
...

After this:

  • open Eclipse
  • "File > Import... > Existing Projects into Workspace"
  • select the project folder

Upvotes: 2

Related Questions