1

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?

2
  • 3
    In Eclipse a Java project requires at least the two XML files .project and .classpath. Do you want to add the project to a workspace in addition? Commented Mar 3, 2019 at 14:41
  • Can you provide a link to those CDT articles? Maybe that processes can be adapted for Java projects. Otherwise I think you could use Maven and the Maven Eclipse plugin to create Maven-based Eclipse projects from the command line (it's no longer maintained though) Commented Mar 3, 2019 at 14:47

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.