Monday, March 24, 2014

The Journey Begins - learning Java (in Eclipse IDE) and Git

Hello my good people!

I really wanted to avoid this, but I am starting to realize that the best way to code and remember what I'm coding (along with configurations and all) is through writing down my experiences and listing my references. Blah, wish I could skip all this and just load everything into my fat brain like in the Matrix. Anywho...learning the new kung-fu (i.e. coding) - begins.

Assignment:  Create a simple Java application and push up into my GitHub repo.

  1. I already have a GitHub account.  https://github.com/gradney
  2. I had to reset the password because I haven't used this since July 2013. Sucks to have to start all over.
  3. Login to GitHub is now successful. I didn't like the duplicate "menbuild" in the online path for MenBuild repo (i.e. https://github.com/gradney/menbuild/menbuild) and deleted this repository. I want this path to look like https://github.com/gradney/menbuild.
    1. To delete GitHub repo, see @ https://help.github.com/articles/deleting-a-repository
  4. In starting all over, I decided to redo the simple GitHub tutorial for starters.
    1. See my results @ https://github.com/gradney/Hello-World
    2. What is Markdown (md)? See more @ http://bywordapp.com/markdown/syntax.html
  5. Next, I opened my Eclipse which I had already connected my Git-specific workspace to GitHub and noticed I still had some old stuff. Since I already deleted the "menbuild" repo, I deleted repo (with its contents) from my Eclipse AFTER I copied any useful files to my Desktop. I was left with the "tester" repo. I'll get to this later.
  6. I started running into a lot of issues with trying to use my existing Eclipse workspace (pointing to C:/User/gradney/git) and pushing projects up to my GitHub. Strangely, I didn't run into issues fetching projects down from my GitHub. Anyhow, tired of being constipated (i.e. running into *push* issues).
  7. I decided that I'm deleting my entire workspace and starting all over with Eclipse. One thing I now realized is what may be significant in keeping Eclipse metadata files separate from Git metadata files. What I had done was make my Git folder also the same as my Eclipse workspace (both pointing to C:/User/gradney/git). From reading the following online article, I'll empty my "git" folder and keep my Git default repository pointing here. On the other hand, I'll create a new workspace specifically for Git projects in Eclipse pointing to C:/User/gradney/workspace/Git.
    1. Using Eclipse with Git, see @ http://www.vogella.com/tutorials/EclipseGit/article.html
  8. Now that I'm starting with a fresh setup with Eclipse (including Git plug-in), I will skip adding the .gitignore file for now. I prefer to keep these files within each Git project because I'm sure there will be specifics later on (according to project's purpose and coding language used) and because I would like to upload this file into GitHub for others to know clearly what all is included in my specific Git projects. In my opinion, anyone who would like to use my projects should be able to fork/fetch my projects (sorry, still learning the lingo of Git world) and run on their local machine w/out any issues.
  9. Let's get to the point of this: Creating a Java project to store in GitHub.
    1. Create a quick Java Project. I'm calling mine "Hello-Java". This will be similar to "Hello-World" done through the GitHub starter tutorial, but this is specific to Java using Eclipse.
    2. How am I doing this? I open the Java Perspective in Eclipse, add a Java Project, create the source files, compile and ensure everything works in Eclipse. (That is, I can run my program in Eclipse.)
    3. Once I finish running my program successfully, I open the Navigator View (since Java Perspective typically opens the Package Explorer). In the Navigator View, I can see all my files in this Hello-Java Project. Here is where I'll want to add my .gitignore file mentioned by Vogella (in link above). I want my .gitignore file to be specific to this Java project. I add this .gitignore file in the Hello-Java folder (not the "bin" folder, not the "src" folder, etc.). It's okay if my other .* files are uploaded like the .classpath because this will help others know what might have also been used to compile my project (like for more complex projects I may use Apache libraries, etc.).
    4. I go back to my tutorial by Vogella and follow through with adding my project my GitHub via Git. I configure my Git Repository as "C:/Users/gradney/git/Java/.git", my Working Directory as "C:/Users/gradney/git/Java". So, I see my Project checked as "Hello-Java", my Current Location as "C:/Users/gradney/workspace/Git/Hello-Java", and my Target Location as "C:/Users/gradney/git/Java/Hello-Java". I click Finish and let's see what happens.
    5. Interesting, I see Eclipse added "[Java NO-HEAD]" to my Hello-Java project in the Navigator View. When I go to my git folder via Windows Explorer, I see a Java folder with a ".git" subfolder and a "Hello-Java" subfolder (with my program). When I go back to my project in Eclipse and right-click on my Hello-Java project and go to Team, I see a bunch of Git commands now. Cool! But wait, I don't see my Hello-Java project in my Eclipse Workspace via Windows Explorer. This is quite strange. Let's continue to see what happens.
    6. Oh no, I just realized something. Maybe my idea of where to place the ".gitignore" file needs to be in the parent folder of the project in git? So, I'll copy my ".gitignore" file from the "Hello-Java" project into the git root folder (C:/Users/gradney/git) and add one line to ignore the RemoteFiles directories.
    7. I continued with seeing the Staging view in Eclipse from Vogella's tutorial, but I'm getting anxious to see how to push my local repository to GitHub. So, I moved forward with going to my "Git Repository Exploring" Perspective, right-clicking on Java repo, selected "Push", ....wait let me keep reading through Vogella's tutorial. Oh shit! I can't create a repo INTO GitHub. I always have to create my repo in GitHub first, and then I can add projects to it.
  10. Let's try again later...
  11. Ok, going through Vogella's Tutorial again - using EGit with GitHub (section 21).
    1. As you can see, I wasted a lot of time already. This sucks! But, I did learn something.
  12. Delete my repository in Eclipse via the Git Repository Explorer. Include deleting from workspace, etc. Check via Windows Explorer that the folders and files are deleted. Checked (and .gitignore file is still in my root git folder).
  13. Following through with Vogella's tutorial and creating a Git Repo on GitHub called "Java".
  14. I copy the HTTPS URL from GitHub to add into Eclipse.
  15. Currently, there are no existing projects in Java Repo, but we'll continue without any projects by saying "next" that we want to import all the existing (zero) projects. Or, we'll just cancel.
  16. Ok, this is not helping.
  17. In Eclipse, go to Git Repository Exploring and add a repository by selecting "Clone a Git repository".
    1. URI:  https://github.com/gradney/Java.git
    2. Host:  github.com
    3. Repository Path:  /gradney/Java.git
    4. Protocol:  https
    5. User:  <myUsername>
    6. Password: <myPassword>
  18. When asked about my Local Destination, I have:
    1. Directory:  C:\Users\gradney\git\Java
    2. Remote Name:  origin
    3. everything else is blank.
  19. Click Finish.
  20. Alright, we have a Git Repo from GitHub. Now, to figure out how to add my project in Eclipse to this repo.
  21. Create a new Java Project.
  22. Once created, right-click and select Team > Share Project...
  23. Select "Git", click Next.
  24. Select Repository:  Java - C:\Users\gradney\git\Java\.git
    1. Leave Working Directory as C:\Users\gradney\git\Java
      1. This is our local Git repository (claimed as our Working Directory).
    2. The following should be stated in the dialog "Configure Git Repository"
      1. Project:  Hello-Java
      2. Current Location:  C:/Users/gradney/workspace/Git/Hello-Java
      3. Target Location:  C:/Users/gradney/git/Java/Hello-Java
  25. Click Finish.
  26. Right-click on Hello-Java project, select Team, select Commit...
  27. Add message into Commit Message, select the Files to commit, and click Commit and Push...
  28. Ok, got an error regarding I'm not authorized.
  29. Let's see, this time I followed through with GitHub's instructions on "Create a new repository on the command line".
  30. I click on my Java repository link in GitHub, and now I see a blank README.md file in my repository. Ok, so my commandline to GitHub is working. But, what about my Java Project to GitHub???
  31. Ok, I'm still getting errors. This just doesn't make sense.
  32. After doing some more searching over the Internet, I found this article @ http://stackoverflow.com/questions/14259265/egit-not-authorized
    1. In the instructions, I would add this clarity:
      1. A. To specify credentials individually for each remote
        1. Open Git Repository Exploring perspective.
        2. Open Git Repositories view.
        3. Expand the git repository. In my case, I had to expand Java [master] repo.
          1. You should see a 'subfolder' (for lack of better word) for Branch, Tags, References, Remotes, and Working Directory.
        4. Expand Remotes subfolder (and see 'origin').
        5. Expand 'origin'.
        6. Right-click on fetching the git repository and select "Change Credentials...".
        7. In the dialog, ensure the Repository is pointing to the desired one (in my case it is "https://github.com/gradney/Java.git") and enter your correct username and password. Click OK.
        8. Do the same for pushing to git repository (by right-clicking on pushing to git repository under 'origin', selecting "Change Credentials..." and entering correct credentials).
  33. Ok, now that we finally resolved the issue with connecting EGit to GitHub, let's see if we can finally create a Java Project and push to my GitHub Java Repo.
  34. In Eclipse, go to Java perspective and create the quick Hello-Java project with a HelloJava class. Make sure it runs without errors.
  35. Once created, right-click and select Team > Share Project...
  36. Select "Git", click Next.
  37. This view is already so much better. My dialog titled "Configure Git Repository" does NOT show the local and destination crap from earlier. Instead, simply has "Use or create repository in parent folder of project" checked, and only the view with the Project, Location, and Repository:
    1. Project:  Hello-Java
    2. Location:  C:\Users\gradney\workspace\Git\Hello-Java
    3. Repository:  ..\..\..\.git
  38. I simply click "Finish".
  39. I see Eclipse is "re-indexing repository gradney" in the lower right corner of my Eclipse screen while the bar is loading. This looks like a good sign.
  40. Waiting for indexing to complete...
  41. Yes, seems to have worked!!! In my Package Explorer (in Eclipse's Java perspective), I finally see the question mark (?) next to my Java project files. This means, in git, that I have new/updated files which are not yet committed and pushed to my repo.
  42. However, when I'm trying to stage my project, I'm running into Java Heap Exceptions in my Eclipse (and my Eclipse is locking up). I decided to add my ".gitignore" file into the Hello-Java project. Eclipse is currently re-indexing.
  43. Ok, so my Eclipse keeps running out of memory because it's trying to stage everything with my one Java project. What a drag! I closed my Eclipse. Well, I added a global .gitignore file into my user folder. I added what Vogella mentions in his article.
    1. Location of my global .gitignore file @ C:/Users/gradney/.gitignore
  44. I open my Eclipse and let's see what happens. The Git Staging view has disappeared. Maybe that's a good thing. Let's see if we can right-click on our Java project and commit.
  45. Nope, still running into issues. Ok, this is just too much. Tomorrow, let's just use another Git client, and only use Eclipse for Java projects. How disappointing. I'm very disappointed with EGit. Not sure what happened from last summer until now. Last summer it was working great. Now, it's garbage.
  46. Or maybe this has something to do with my work machine. 
I almost forgot to say some important specs (i.e. specifications). Here's the software I'm using:
  • My operating system is - Windows 7
  • Java 7 - jdk1.7.0_21
  • IDE, not sure of the version, but using - Eclipse IDE Juno
    • don't forget the Git plugin
  • Git version 1.8.1.msysgit.1
  • PSPad (my favorite text editor)


No comments:

Post a Comment