How to include a git submodule into a project? - eclipse

So I have a git repository for a few related Java classes with a folder structure similar to this:
mylib/LICENSE
mylib/README
mylib/src/file1.java
mylib/src/file2.java
mylib/test/tester.java
...
Now, I'm creating an Android app in Eclipse with the traditional folder structure like:
repo/AndroidManifest.xml
repo/bin/*****
repo/res/*****
repo/src/com/mysite/project/activity1.java
...
Now, I'd like to add the java classes to my android project in the folder:
repo/src/com/mysite/mylib/file1.java
However, if I add it as a git submodule, they are saved to the path:
repo/src/com/mysite/mylib/src/file1.java
Also, included is the tester.java, and some other files I don't want in the Android project.
What is the best way to resolve this? Should I just leave the path as com/mysite/mylib/src/file1.java? Or should I modify the repo and move the files from mylib/src up into mylib and delete the files I don't want?

The simplest way would be to:
keep your original (non-Android) repo separate
add that original repo 'src' folder as a source folder of your Android Eclipse project (an Eclipse project can defined several src folders, from various origin)
That will sidestep the "submodule" issue entirely, and allow you to select from your original project only the files you need for your Eclipse Android project.

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.

How can I create a project in the Git repository root using Eclipse EGit?

I would like to add the project files of a brand-new Eclipse project to the root-level of a git repo. I would like it to look like something like this:
./projectrepo/.git
./projectrepo/.project
./projectrepo/src
...
However, the Eclipse Egit wizard provides no obvious way to do that, and insists on creating an undesired subdirectory (screenshots below):
./projectrepo/project/.git
./projectrepo/project/.project
./projectrepo/project/src
...
How can I get Eclipse to add my files at the repository root?
I understand that the Egit manual advises against this, but I do not plan to ever have multiple projects in this repository, so the extra directory is unnecessary (and counts against filesystem path limits on Windows). The fact that it's advised against tells me it must be possible somehow (or the documentation's wrong).
System information:
Windows 7 64-bit
Eclipse Oxygen Java EE (4.7.0 Build id: 20170620-1800)
Eclipse EGit 4.8.0.201706111038-r
Screenshots of Eclipse's current undesired behavior
Configure Git Repository wizard. Most of the things I'd like to change, like Target Location, are uneditable. Path within repository can only be used to add more extra folders. Use or create repository in parent folder of project has a freetext repository path input, but only parent folders will validate and can be used.
Resulting undesired Git repository structure. I would like my project files to be in this directory, not an extra "TestProject" folder:
Try instead to:
import your project into your Eclipse workspace
then use Team/Share project: it should detect the Git repo in it.
That way, you should avoid the double-folder creation.

Can a folder that is in a Git repo be imported into Eclipse if it is not part of a project?

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.

Do i run git init in the src folder or in the project folder of my workspace?

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.

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).