Archive for January, 2014

GitHub: working with the git command line on Windows

This tutorial will allow you to upload your project on the github repository.

I am a linux fan but I have to work with Microsoft Windows. Git is integrated in the Eclipse IDE, but I want to learn to use it by command line, to learn the commands in a better way.

Reality is a bit tougher on the shell. I know about setting SSH keys on Linux. I have already blogged about it on this site, but I have decided to use the Github software provided for Windows.

The steps are the following:

1) install git to run the commands by shell. You can get the installer for Windows at: https://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git

2) download and install github client, that you can find at https://help.github.com/articles/set-up-git

3) run the Github client and login with your github account credentials. The software will create a .ssh folder with your rsa git keys automatically, so you won´t have to worry about passwords and keys. Just use the github software and the provided shell.

4) create a github repository from the github website or the installed client: for example “Hibernate_Demo” (Github client, figure 1).

Figure 1

5) clone the project locally (Github client,figure 2).

Figure 2

6) click on the project name in github and openshell by clicking on “tools and options>open shell here” (Github client, figure 3).

Figure 3

7) Navigate on the shell to your project on your desktop. For example:

C:\Users\liparulol\workspace\hb_project>

You can now work on the github shell directly.

8) Run the command “git init” to inizialize a local repository for the hb_project and check the status with “git status”.

9) Run the command “git add *” or “git add .” to tell git to commit all the files and directories in the project folder

10) Commit all the added files, adding a message running: 

git commit -m "Add all content"

You can check your last activity with the “git log” command

11) Add a new remote repository of your project:

git remote add origin [email protected]:lauraliparulo/https://github.com/laurliparulo/Hibernate_Demo.git

12) If the created repository contains file that are not on the local master run:

git merge origin/master

13) The you can finally push your project to the repository with the following command:
git push origin master

You should see the project on the github site. It takes some time to see the changes on your github client locally…

You can also manage your git project by running “gitk", which will open a Python revision browser.

Ant task to execute a main class with command line args parameters

Yeah, once again another HelloWorld stuff on the web. I was just curious to try to execute a Main class with an Ant script and found out that I couldn´t find the straight working snippets online easily, because I couldn´t get to know how to set the classpath. So I have wasted some minutes to make it work.

Let´s consider a little more than the classic HelloWorld example and pass a command line parameter as well:

package de.demo;

public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello Main! \n"  + "Parameter: "+ args[0]);
}

}

Then run following build.xml script:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<project basedir="." default="run" name="Ant Hello World">
	
	<property name="src" value="." />

	<path id="classpath">
		<fileset dir="${src}">
		</fileset>
	</path>

	<target name="compile">
		<javac srcdir="." />
	</target>

	<target name="run" depends="compile">
		<!-- Print directly in the console -->
		<echo message="Hello World!" />
		<!-- Run main class with parameters-->
		<java classname="de.demo.HelloWorld">
			<arg value="10"/>
			<classpath refid="classpath">
			</classpath>
		</java>
	</target>

</project>

In the console you will see something like:

Buildfile: C:\Users\liparulol\workspace\AntDemos\buildHelloWorld.xml
compile:
[javac] C:\Users\liparulol\workspace\AntDemos\buildHelloWorld.xml:14: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file
run:
[echo] Hello World!
1 Hello Main!
1 Parameter10
BUILD SUCCESSFUL
Total time: 745 milliseconds

That´s it!

Categories
Links: