non build files of eclipse project in git repository - java

I have files that are associated with my Android project, that are not needed for the build. For example .svg files to generate icons, README file, apk files etc.
Since i would like these files to be part of my project's local git repository(and GitHub), where can i place them? If i place them inside the project folder, it shows up in the Project Explorer in Eclipse. I wonder if it then becomes part of the build and therefore the apk. Is there a convention for this?

If there are files/directories that you do not want to push to the repository, you should use the .gitignore file.
Create a .gitgnore file in the root directory of the git project. This is what a typical .gitignore file looks like in case of android.
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
You can add options similar to these as required. E.g *.svg if you want to ignore svg files.
For files that are already added to your git repo, you'll need to use the git rm command to remove them from being tracked.
e.g git rm bin *.svg
Then use git add and commit as usual. All files matching the criteria in the .gitgnore file will not be tracked in any future commits.

Placing them in a subfolder in the project folder should work.
I have tested this by placing a subfolder svg with 19 .svg files totalling 100 kb in my project folder. The resulting .apk was the exact same size as before. So ADT's building process is intelligent enough to ignore miscellaneous folders.

Related

how to remove unwanted files from maven project

I am currently working with a spring web project. In my project, i am using git,maven and eclipse as IDE. when viewing git status in terminal these three files are present in all cases:
.classpath
.gitignore
.settings
how can in remove these unwanted files. i have no idea how these present in my project. my colleagues have also experiencing this issue.
any suggestions will be helpful.
As its a git repository, you can include below lines in your .gitignore file and then commit your .gitignore file to your central git repository, after that your local git repository won't show the ignore files which you added.
.settings
.classpath
Read more about .gitignore here https://help.github.com/articles/ignoring-files/.
Edit :- You these files are already unchecked then you need to run below command (If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:) :-
git rm --cached FILENAME
So in you case above command will look like git rm --cached .classpath and git rm --cached .settings.
Create .gitignore file in your project root directory and specify file path you want to untrack, for example:
.classpath
.project
.settings
target/
.mvn/
As other guys mentioned - you should add .gitignore file to the root of the project. There is a good Github project - gitignore. You could concat this files into one:
Java.gitignore
Maven.gitignore
Eclipse.gitignore
You could read more about .gitignore in a project description
You can directly open your workspace and open your project, after that you can manually delete those files... Make sure you check "show hidden files" if you are using windows and before deleting please close eclipse and then remove the files.
In SVN Repository can use Add to svn:ignore. using this one can remove unwanted files.

How to not push certain directories/files to Github?

Specifically for Java Eclipse projects.
Is there a reason to have anything other than src and lib directories on github??
How much value does providing /bin, /settings .classpath, .project, etc.??
I'd like to have them on my local, but not displayed on github. Is there a way to do this?
Thanks!
EDIT:
contents of my .gitignore file (which is located in my local git project directory):
bin/
.settings/
.classpath
.project
I did a git add (to add this new .gitignore file) and a git commit to my local repo.
However, when I push to my remote github (https://github.com/VKkaps/Breakout) now, I still see everything including the .gitignore file now? Help?
The answer is .gitignore file.
See: https://git-scm.com/docs/gitignore for more information.
If you don't want the .gitignore file in the repo another option is Git's exclude file. This file works similar to a .gitignore file but isn't committed to the repo.
From the Github docs:
You can use this technique for locally-generated files that you don't
expect other users to generate, such as files created by your editor.
Use your favorite text editor to open the file called
.git/info/exclude within the root of your Git repository. Any rule you
add here will not be checked in, and will only ignore files for your
local repository.
In Terminal, navigate to the location of your Git repository Using
your favorite text editor, open the file .git/info/exclude Add rules
to the exclude file as you would the .gitignore file

how can i ignore the .idea folder in .gitignore file?

I ignored the .idea folder(for intellij IDE), all file and folder that is in the .idea is removed. I am seeing the .idea in intellij but no this folder in github. And also when i clone this project there is no again .idea, because of it this project is not working on intellij idea project. I am not adding new developer.
Git doesn't track directories, it tracks only files. When you untrack all files from within a directory, you are in essence untracking the directory as well.
If you want to keep the directory around in your repository on other machines, while ignoring all the files within it, you could add an empty dummy .gitkeep file.
However, since the desired behavior is to not track any files within the directory, we can use a directory specific .gitignore as the dummy file here which has a single ignore rule for ignoring everything.
So, basically, this translates into the following commands:
$ cd $PROJECT_DIR
$ echo "*" >> .idea/.gitignore
$ git add -f .idea/.gitignore && git commit -m "Ignoring all files within .idea"

Indecision on which files to upload on GitHub

I have a java project made with Eclipse.
While working on a project, Eclipse creates a bunch of files and folders, what folder and files should I upload on GitHub?
I think that everything under the src folder should be uploaded. Am I right? Should I commit the .java or the .class files?
source control such as git are used to commit anything that can be called as source and not environment specific. So code, related resources should go but any IDE specific files.
Use gitignore either project specific or globally. The easiest way is to create a .gitignore file in your project root repository. For instance
# Eclipse
.classpath
.project
.settings/
# Intellij
.idea/
*.iml
*.iws
out/
artifacts/
# Mac
.DS_Store
# Maven
log/
target/
It depends on which files do you want to share too.
For example, in my current company almost all my colleagues and I use Eclipse, so we have repositoried .project" and .classpath too. It is very handy because changes in .classpath are done only once, and then propagated to all developers.
If your root folder is both the git repo root and your workspace, you won't probably want to upload the .metadata folder, since it contains settings specific to each different developer. And, by all means, you will want to ignore Eclipse's compiled directory (typically /bin).
Think about what do you want to share and/or version, and that will probably give you a list of things to upload/ignore.
Edit: as said before, upload ONLY .java files, .class files are products of your source code, and have to be generated, not stored.

Eclipse JAR export settings for external JAR file creation(for import into another project)

I have a project where I want to add an external JAR file. The desired external JAR file has a nifty Github page with source, but no pre-compiled JAR file.
These are the steps I've completed so far:
1. I have downloaded the source in a zip. (its Twinkle from SwingFx.ch in case you're interested)
2. I have extracted the zip file to my workspace.
3. I have created a new project with the same name as the extracted folder from the zip file. (project loads the source successfully)
4. I select the export option from the File menu and selected the 'JAR file' option and clicked next.
Note: I had to add an external library to the above Twinkle project for it to build successfully (in case that makes a difference to the settings).
On the JAR File Specification page there are multiple check-box options available(see below):
Export generated class file and resources
Export all output folder for checked projects
Export Java source files and resources
Export refactorings for checked projects
Compress the contents of the JAR file
Add directory entries
I am not sure which are supposed to be selected and if it makes a difference in the behaviour of the project I will add the (soon-to-be) exported JAR file to. I tested it by exporting with the default settings. This worked ok.. However, I now do not know if I should have chosen different settings in case of any reasons I am not aware of. I am not sure if there are specific settings I should choose when I intend for the JAR file to, specifically, be added as an external JAR file to another project.
Please enlighten me!
This is a traditional Java library that uses Maven. It should be fairly easy to build using Maven, which should be better and quicker to build this, if you already have Maven and git installed.
Let's consider that you did not download the source file as a zip, but take the github approach, where you'd use git to download the source code.
If you don't have git, download its latest version and install it.
If you don't have Maven, download its latest version and install it.
Once Maven and git are installed, make sure the Maven and git binaries are configured in your environment PATH variable. If not set, you would, on the Windows platform and for Maven binaries, set it this way (using the default installation path):
set PATH=%PATH%;C:\Program Files (x86)\Apache\maven-3.1.1\bin
Create and change directory in a work directory of your choice, that we'll refer to %work_directory% from now on.
Run the following:
cd %work_directory%
git clone https://github.com/spreiter301/Core.git
git clone https://github.com/spreiter301/Twinkle.git
cd Core
mvn clean install
cd ../Twinkle
mvn package
6. Retrieve the twinkle-1.0.0.jar file in the newly created '%work_directory%/Twinkle/target' folder.
In this case, it was necessary to retrieve the Core library because it is a dependency of the Twinkle project. Normally, this is not necessary because dependencies are automatically retrieved from a maven repository. But in that case, that dependency is not available on any Maven repository. Hence we manually retrieved the dependency from github, compiled it and installed it in your local cached repository. Then we could package the Twinkle project into the JAR file.
This should do it. If you want a 5 minutes tutorial on Maven, there is a tutorial for this here. I highly recommend it, you will encounter this often in the Java world. Maven is the standard build tool for Java, just like 'make' is for C, 'rake' for Ruby, 'sbt' for Scala, etc..! Good luck with the rest.

Categories

Resources