Can I convert eclipse source folders into packages?

前端 未结 3 1201
借酒劲吻你
借酒劲吻你 2020-12-21 12:34

I\'ve forked a Github project, used Eclipse to clone it locally, and imported that as a general project into Eclipse. The accompanying .project file is an Eclipse .project

相关标签:
3条回答
  • 2020-12-21 12:59

    What you did is you have probably cloned the repo in Eclipse and then Imported this project through a New Project Wizard, because in GitHub there is no existing .project (and no .classpath) files.

    The "New Project Wizard" will create a set of defaults for a java project (I suspect that you selected just that), but is anaware of Maven structure, so all source folders will not be recognized and you will end up having to define them on your own. Worse, you will be unaware of any special parts of the Maven build that might be configured within pom.xml.

    Because this project uses Maven for building, it would be better to use M2Eclipse while importing it. Install it using Help->Install new software.

    Then there are a couple of steps required to make it use all Eclipse features.

    Keep your cloned copy of the repository or clone again if you want to start from scratch. Then use File->Import feature to import a maven project into the workspace. Select Exisiting Maven Projects and point to the directory containing pom.xml file in the cloned repo. This will use Maven integration in Eclipse to generate .project and .classpath files based on pom.xml contents, so you will be able to more closely mimic Maven build in Eclipse. All source folders should be properly discovered this way. Eclipse might want to install some additional integrations for Maven features that this particular project uses. Let it, if that is the case.

    Now, you will have the project operational and compiling in Eclipse, but it will not be aware that it is managed by Git... This is because M2Eclipse and Git Team provider are not integrated (at least they weren't when I last checked). In order to be able to commit to the repository in Eclipse, remove the project from workspace, but without deleting contents. Then, import from Repository view using Import Projects/Import exsisting Eclipse projects. Since necessary .project file is already generated, Eclipse will autodiscover the project and will use the right configuration prepared earlier by M2Eclipse.

    In the end you will have a properly configured Maven project with Git as a team provider for it.

    0 讨论(0)
  • 2020-12-21 13:11

    Right click at root of project select properties, in the sources tab add the folder "src/main/java" as source folder

    Other way is to configure facet as java

    facet

    0 讨论(0)
  • 2020-12-21 13:15

    If this is a project meant to be built by Maven that contains a pom.xml file, install M2E before importing the project from your local cloned repository. It will handle this.

    0 讨论(0)
提交回复
热议问题