How to connect/sync just the src folder of the maven project in eclipse workspace to src folder in repository - eclipse

I have commited just the src folder and pom.xml of maven project into SVN repository in order to make it independent of IDE (As .settings, .project etc are files specific to eclipse ide)
Then when I'm trying to import the src folder in a newly created maven project (as it has the other files which are needed to run the project in eclipse), basically I only want to synchronize the src folder and pom.xml with the repository, I get a warning while I import the src folder 'as a folder in existing project' AS 'Destination project is detached from the source control. So please take into consideration that the plug-in won't provide any SVN actions for these resources' and then I'm not able to use Compare with and Team Options. It doesn't even show the revision no. besides the imported class files and folders.
Is there a way to do this ??
What is/are the usual industry practice/s ??

There're 2 options.
1.) Check out the SVN files using some other tool e.g. (TortoiseSVN) and then import the maven project using 'Materialize Maven Project'. This will create necessary metadata for eclipse and will also maintain the version info for the checked out project. See this reference http://www.sonatype.com/books/m2eclipse-book/reference/creating-sect-importing-projects.html
2.) The (better) other way is to download 'Maven SVN Integration' plugin using update site
http://m2eclipse.sonatype.org/sites/m2e-extras/. Once you install the plugin, you would be able to see option 'Check out as Maven Project' in SVN repository exploring perspective.
Thanks,
Prabhjot

Related

Using a separated source folder from SVN on Eclipse

So, here in the company we work with svn, and our svn server only have the source folder. When I use NetBeans, it's everything ok because I can add source folders in project and will work fine in svn. But on eclipse if i do the checkout from command line and add that folder in my dynamic web project, I can't see the svn history and nothing, svnclipse just does not work on that folder.
Our structure of the projects it's something like this
Workspace
Project folder
Project1
Project configuration files
SourceCode
Packages
Project folder 2
Project2
SourceCode
I already try to make checkout using svnclipse, but he add alot of extra config files, he turns the folder in a project and the source folder is add as a link to another project, in this scenario the svnclipse quick diff does not work properly.
There is a way to use that folder as source and Svnclipse works on that ?
Sorry if my English is not so good
There is no easy way to do what you want. In Eclipse a source control provider can only be connected to the project itself. So options are:
Use another svn client like command line or TortoiseSVN.
Create a small SVN project with the Eclipse project configuration files that also use svn:externals to pull in your source folder from repository.
With option 2, you would checkout this small SVN project from some other repository using Subclipse in Eclipse, could even be a local file:// repository and then the svn:externals property would also cause your source folder to be checked out.

Importing GIT project into eclipse mangles package names

I'm trying to import a GIT repository into my eclipse (luna, 4.4).
The imported packages have "src" prefixed to the correct package name.
E.g. instead of com.myproject.test I see src.com.myproject.test.
I'm a GIT newbie. Any insight is greatly appreciated.
Your .classpath file was not committed into the repository, so Eclipse does not correctly know where the root of your sources are. Bring up the project's Properties Dialog (use the context menu or the main menubar's Project menu) and go to the Java Build Path page. On its Source tab, you can remove the project folder itself and set src as the Source Folder to use (not that you're limited to just one in the future).

SVN Checkout of multi module maven project causing build issues

I am trying to learn how to setup multi-module maven project and share it with colleagues using SVN.
We work with eclipse IDE.
Here is how my project structure looks in SVN.
Each module has its own svn labels and tag trunk, branches, tags etc.
I check out all the modules individually by right clicking on them and choosing check out.
Finally I get the below in my eclipse project explorer:
Here is my pom for the parent project. and this throws errors when I do a mvn clean install
I want to understand how to checkout the projects/ modify my pom to get the build successful.
Thanks
You don't want to check out the root folders of your modules in SVN. All you want is the content of the trunk. So right click on the trunk folder and select Check out as.... Check it out as new projects and enable Maven on those project afterwards. Do this with each of your modules and you should be fine.
If you have Maven SVN connectors installed you have an option called Check out as Maven project. This is very comfortable as it does a few steps for you.

m2e and project metadata files

I'm used to other IDEs such as Visual Studio which keep project structure on some metadata files. I'm using Eclipse right now and I used m2e eclipse to import a maven project. afaik Eclipse only gets source/resource files from pom.xml (or maven default directories if none is specified) and create the project tree.
Therefore, i think that, if I have the code and Eclipse configuration files (.project, .classpath) in a repository and I update code directory structure, no Eclipse files will be updated and therefore I don't need to update Eclipse files in the repository.
Is that correct?
Correct, you don't need to save the .project and ,class path files in a repository. The m2e commands "Update Project Configuration" and "Update Project Dependencies" will correct those files, respectively, once you've retrieved the rest of the source from the repository.
Generally, if you use m2e (recent versions) and a SCM (Git, Svn, CVS, etc.), you don't need to commit the Eclipse configuration files to the repository.
These main files are :
.project
.classpath
.settings/
There is a good example on GitHub of a .gitignore file which shows what files in Eclipse you don't need to commit.
EDIT :
To regenerate Eclipse project files, you can either :
Import > Existing Maven Projects : needed eclipse files are created
Import > Checkout Projects from SVN (or CVS, GIT, etc.) ..... if needed : Convert to Maven project
Use CLI maven-eclipse-plugin with mvn eclipse:eclipse (Goal) (not recommended if using m2e)

Importing a Maven project into Eclipse from Git

How can I get the effect of choosing to import from both Maven and Git and have Eclipse properly generate my project?
To get my project into Eclipse I can choose File->import->maven and then I get all the Maven projects imported and can build fine, or I can choose File->import->git and make a new project that ignores the pom.xml and does not generate the project properly.
It seems I can do one or the other but not combine both so I get a correctly generated project.
Eclipse Indigo + M2Eclipse 1.0 makes it very easy.
If you don't already have the Git connector for M2Eclipse install it. M2Eclipse will help you along by prompting you on the Import menu.
Select the "Import..." context menu from the Package Explorer view
Select "Check out Maven projects from SCM" option under the Maven category
On the window that is presented choose the link "Find more SCM connectors in the m2e Marketplace
Find connector for Git...install...restart
Note that in the search box you may have to enter "EGit" instead of "Git" to find the right connector.
With that done, simply go to the EGit repository, bring up the context menu for the Working directory and select "Import Maven projects...".
Done!
I would perform a git clone via the command line (outside Eclipse) then use File -> Import... -> Existing Maven Projects.
Your projects will be understood as using Git and Maven. It's the fastest and most reliable way to import IMO.
Step 1 : Setting Up Eclipse
First of all you'll need to have a few Eclipse plug-ins installed. So use eclipse IDE software install feature in the help dropdown menu → Install new software, and add link to Available Software Site, then install it.
GIT plugin (EGIT)- http://download.eclipse.org/egit/updates
Eclipse Maven plugin (M2Eclipse) - http://download.eclipse.org/technology/m2e/releases
Maven SCM Handler for EGit (m2e-egit)
Install from the M2E Marketplace (Settings → Maven → Discovery → Open Catalog and search for " m2e-egit")
Step 2 : Clone the repository
Clone(download) your Maven Projects from Git
Check out non-eclipse Maven Projects from Git (File → Import.. → Maven → Check out Maven Projects from SCM)
Now add your git repository link to SCM URI field.Then click next & finish.
As of this (updated) writing, a working setup is the following:
Eclipse 3.8 (Eclipse Indigo update site)
EGit 1.3.0 (Eclipse Indigo update site)
m2e 1.0.200 (Eclipse Indigo update site)
m2e-egit 0.14.0 (m2e marketplace when adding a connector)
Tested on Ubuntu Raring.
You can certainly "Import" -> "Maven" -> "Check out Maven Projects from SCM", and this is the quickest way. However, such direct import currently does not give you control over the cloned repository folder name. You may be better off working from the "Git Repository" View and perform either a "Clone from a Git Repository and add the clone to this view", followed by an "Import Maven Projects" from such clone; the longest way would be to do your manual cloning and then "Add an existing local Git Repository to this view", followed again by an "Import Maven Projects". Either case you have full control on the cloned folder.
A final comment on a side issue that made me cry in frustration. As far as I know, if the cloned repository lies on the root of your Eclipse workspace, and your Maven project file hierarchy has a POM on its root, then importing such root project will rename the cloned folder (with the template you chose, defaults to [artifactId]). Without changing your project structure and without keeping files outside your workspace, you can easily work around this issue by cloning on a subsubfolder of the workspace folder.
I have been testing this out for my project.
Eclispe Indigo
"Help > Install New Software" Enable/Install official Git plug-ins at "Eclipse Git Plugin .." and install the lot.
Enable the Maven/EGit connector with these instructions How do you get git integration working with m2eclipse?
Switch to the Git Repository perspective. Right click paste the project git url. The defaults should all work. You may want to change the install folder it guesses.
Expand the cloned repository and right click on "Working Tree" and pick "Import Maven Projects...".
Switch to the Java perspective. Right click on the project and choose "Team > Share Project". Select "Git" and be sure to tick the box "Use or create repository in parent folder of project".
Here's my workaround, this is a solution to these issues:
You can't install m2e-egit (I get an error in Juno)
Converting a general project (connected to your Git repository) to a Maven project isn't working for you (The Import Maven Projects step seems essential)
Importing Maven Projects from your repository on the filesystem isn't showing the project connected to Git.
Setup your Git repository in the Git Repository Exploring perspective.
Switch to the Java perspective, Import > Existing Maven Projects
Browse to your Git checkout in the filesystem, select the directory containing the pom.xml file. Finish the import;
you'll notice these projects aren't connected to Git. :-(
Delete these projects, but DO NOT DELETE FROM FILESYSTEM.
We don't want our clone deleted; this task also leaves the .project file behind so that we can import in the next step.
Go back to the Git Repository Exploring perspective.
Right-click your repository, Import Projects...
Select Import existing projects
In the explorer below, browse to and select the directory containing the pom.xml (and .project file) , then click next.
Continue through the wizard.
Import without installing any additional connectors for Mylyn:
Open Git Repositories view (Window->Show view->Git Repositories)
Press Clone a Git Repository button and proceed with all steps
In newly created repository expand Working Directory, right click on folder with your project and select Import Projects. Then either choose Import existing projects, or select Import as general project. If needed after importing right click on your project and select Configure->Convert to Maven Project (and Maven->Update Project).
You should note that putting generated metadata under version control (let it be git or any other scm), is not a very good idea if there are more than one developer working on the codebase. Two developers may have a totally different project or classpath setup. Just as a heads up in case you intends to share the code at some time...
I have a maven project with three submodules that is managed in git. I set them up in eclipse as follows:
I registered the git repository with eclipse using EGit
I imported the projects as existing Maven Projects
For each project, I went Team | Share Project.
Direct answer: Go to Files>>Import>>Git>>Project From Git (you should have GIT installed on Eclips)
I would prefer to import projects into Eclipse as maven projects rather than git project. Doing this will still allow the project contents to be recognized as git contents. You can continue to perform git operations from Eclipse. As you have mentioned the reverse is not true.
The nature of a project in Eclipse is not based on the SCM which holds the project, but on the type of project - whether war or jar, etc. - which is automagically determined when the project is imported as maven project.
I would be hesitant to check-in to SCM IDE-specific metadata. Doing so assumes a lot of things - all developers are using the same IDE or version of the IDE, perhaps same version of JDK/JRE, that they continue to use the same version throughout the project lifecycle and so on.
Can't you import it as a git project and then (if you have the m2eclipse installed) right click on the project in the Package Explorer > Maven > Enable Dependency Management?
After checking out my branch in Egit, I switched to the Java View, then used File-->Import, Git-->Projects from Git, then selected the top level maven directory. This was with Eclipse Kepler.
Instead of constantly generating project metadata via import->maven command, you can generate your project metadata once and the place it in your git repository along with the rest of your source code. After than, using import->git command will import a proper maven-enabled project, assuming you have maven tools installed.
Make sure to place into the source control system all files in project dir that start with '.' such as .classpath and .project along with the entire contents of the .settings directory.