简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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