I am working following a set of java swing tutorials, each is an Eclipse project, keep them in a workspace. I init a git repository in the workspace folder (mac), and upload to github. When I download this folder in another computer (linux), the projects are not recognized as such, and opening/importing in Eclipse fails. Says: 'Folder not recognized as project'. What is the best way to handle a collection of projects in git?
If you want to have all of your Eclipse project data across your machines, you will have to add the following files/folders to Git:
.classpath
.project
.settings (folder)
Make sure that these are not ignored in either your local or globale .gitignore files.
Ignore things like the bin and target folders, since they contain the compiled classes and shouldn't be added to Git.
Regarding the failed import: as #nwinkler writes, Eclipse looks for the .project and .classpath files so you need to add them (and the .settings directory) to your git repository.
Regarding .gitignore, I typically put the workspace stuff there (and then do import existing projects in eclipse after cloning):
That is,
.metadata/.plugins
.metadata/.lock
.metadata/.log
and then for each project, the bin folder
project_dir/bin
and any other generated files
Related
I installed a fresh copy of eclipse Neon, and created a new gradle java project in a new and shiny workspace. What is the best practice for adding git to the party?
I read that initializing git in the project directory is really a bad idea.
What is a particularly good idea then?!
Thanks!
The good idea is to git init a parent folder of the project different from the main workspace folder.
This is exactly what happens if you let Egit git init your project (Right click on project -> Team -> Share Project -> Git ->...) and select an external folder as repository, say c:\users\john\my-git-repository.
You will then have two folders:
c:\users\john\my-git-repository containing the \.git folder and \<my-project> folder
c:\users\john\<eclipse-workspace> the eclipse workspace folder, which will NOT contain your project folder (remember that eclipse workspace is just a logical container for projects, they don't need to be physically there).
Another option is to create a folder inside the workspace, create the project as a subfolder of that folder and then git init that folder. This way:
c:\users\john\<eclipse-workspace>\shared-projects\<my-project>
You will create the repository in the \shared-projects folder (either by command line with git init or from whithin Eclipse with the wizard), which will contain the \.git folder, \<my-project> folder and any other project you want to share.
Remember why Eclipse suggests to keep repositories outside the workspace (https://wiki.eclipse.org/EGit/User_Guide#Creating_Repositories):
It is a good idea to keep your Repository outside of your Eclipse Workspace.
There are several reasons for this:
The new Repository will consider the complete folder structure of the Eclipse workspace as (potential) content. This can result in performance issues, for example when calculating the changes before committing (which will scan the complete .metadata folder, for example)
If your git repo is in the \shared-projects folder the repository will NOT consider the complete folder structure of the Eclipse workspace as (potential) content and will NOT scan the .metadata folder since it's outside the repo. The only contents of the repo will be your shared projects!
There is a folder in a Git repo which holds a bunch of sql scripts but the folder is not part of any project. When I try to create a folder in Eclipse it seems to require that I specify an existing project for it to be a subfolder of. Is that always required or can a folder exist at the same level as the projects, with no project for it to be under?
Everything in an Eclipse workspace must be in a project. Folders cannot be at the same level as a project.
I couldn't find a question that similar to mine but the point I'm asking is where do I run git init? Do I run it in the src folder where my code is or in the project folder which contain the src folder and a bin folder? I'm working with eclipse and gitBash. Hope this is enough info.
What do you mean by builded project? Are you referring to .classpath, .project, .settings
When you create a repo, you need to include anything needed to actually build the project.
That include the src/ folder, but also other configuration files.
Those can include the .project (if it has only relative paths, easily reused by others), and the .classpath: see ".classpath and .project - check into version control or not?".
The settings/ folder can also be included 5see "Which eclipse files belong under Version Control", but not the .metadata/ subfolder.
It even can include settings for other IDEs like IntelliJ IDEA, if other contributors are using that tool.
It would not include the bin/ folder, typically added in a .gitignore, because its content is regenerated on demand (built).
Run it in the Project folder.
src folder contains the code files mostly. But supporting resources may be included in the other folders. And you will need to add everything to git without which project may have problem running.
What files should I commit to github so that its a valid Eclipse project ?
I am just committing my source files and packages but when I try to re-create the project I receive this error 'no projects found' :
I think I need to also commit the .project file ?
You need to commit your:
.settings dir
.classpath file
.project file
The better idea will be to use maven for your project so that
you will have a common configuration for all the IDEs (eclipse, netbeans, ideaj ...) and no need to push your eclipse specific configuration.
For a typical Java SE Eclipse project, you must commit .project and .classpath files, but not necessary .settings folder. I tested this scenario by committing one project from my windows environment and cloning that onto my Linux environment; Eclipse imported and run this project without any error. Hope this tip helps you reduce committing one folder (the .setting).
I have some projects on bzr code repositories shared with colleagues.
Problem is, I really want to switch to eclipse in some projects, but I don't want to pollute the repository with the unnecessary metadata eclipse creates in its Workspaces.
Any idea how to keep Eclipse's metadata outside my bzr repo?
Adam
If you know the names of the meta files created, you could put them into your .bzrignore file in your repository's directory.
See this part of the bzr docs
All the main metadata in eclipse are in the workspace.
You project, meaning:
your .project file
your .classpath file
your .settings directory
your source files
should all be located elsewhere, within your main project directory.
All those files (except the .class files generated by the compilation) should be versioned.
See "Do you keep your project files under version control?" for more, but also:
What to put under version control?
When working with Eclipse, should I add the workspace to the source control?