Connect to Github via Netbeans

Create remote git repository

You need to create new github repository before you can connect local repository to it. Of course you need to have an account on github, but it’s not an issue, it’s free.


On the remote repository find https address of your project and save it for later.


Create local git repository

After creating new project in Netbeans you need to initialize local git repository.

Define exceptions – .gitignore file

But before you do that, create “.gitignore” file where you define all exceptions. In the source control we usually save only code files and configurations, but not binary files, IDE specific files etc.  The file must be in the project root folder.

You can always delete exceptions from “gitignore” file and add files to repository later.


At project node, with the right click, select “Versioning” and “Initialize Git repository“.  Initialization procedure add all files in the project, except ignored ones,  to the local repository. Adding a file only mark file for version control. File is not in version control until is committed to.


Commit to local repository

Your files need to be committed to local repository. With right click on project node, select “Git” and “Commit”.  This will create local branch in local repository which will you connect to github.

2016-11-26-23_49_55-planitia-no-branchIn the repository browser (/Team/Repository/Repository Browser) you see current state of local git:


Pull from remote repository

Because you already commit to remote repository, that’s because of automatically added and licence files, you must pull those files first and MERGE them to the local repository.  Then you will be able to push all local differences back to remote repository.

2016-11-27-00_27_14-jump-list-for-mozilla-firefoxEnter project URL (https://….), username and password.


Connect branch with local origin branch where files will be synchronized from remote server.

2016-11-27-00_28_25-pull-from-remote-repository And finish. You will merge new files ( and licence) from remote to local git.

Push to remote repository

After you pull new files down or if you didn’t have any to pull, you continue with push.

Select right click on project node and execute Git/Remote/Push.

2016-11-26-23_56_45-jump-list-for-mozilla-firefoxConfigure  URL of your project (https://….), username and password.


Select local branch to push.


And select local origin branch where remote repository is replicated. 2016-11-27-00_42_08-push-to-remote-repositoryClick Finish and your files will be sent to remote github repository.

Verify remote git repository

If everything went right, you will see all your project files and folders on the github and two new files inside your local project.

2016-11-27-01_11_41-bisaga_planitia_-this-is-another-test-project-to-see-how-new-stuff-working-togetThat’s it ! You are connected to new github repository.

TomEE: Java EE server database configuration

Configure database access

I use Apache TomEE server and therefore I need to configure it for database purpose before first use.

Install database driver

Drop database driver jar file in tomee/lib folder.

Configure datasource

Resources are usually defined in  server configuration file.

Add datasource resource definition in configuration file located in  tomee/conf/tomee.xml.

Verify configuration

After server (tomee service) restart, search for your datasource in log (example log file: tomee/logs/catalina.2016-11-26.log). You will find log entry with your resource id there:

If you restart server from inside netbeans,  just search in output window where log entries are shown.

Inject datasource in java code and use it

To inject instance of datasource where connection is needed you simply add annotation “@Resource” above variable declaration:

Let’s see whole example with select statement (jOOQ):

This example code is called from REST JSON service and result in the browser looks like this:


JOOQ – database access layer

Add Java object oriented querying – JOOQ – to project

I love “database first” principle when talking to database. Why would I sacrifice majority of SQL powers, just to talk to database with some ORM technology ? Of course it depend on so many factors, but if you need something very close to database, JOOQ is a way to go.

JOOQ is open source if you use it with open source databases (MySql, Postgres, etc.) !

Configuration and setup

You need to download jooq library and unzip it to some folder (H:\JavaLib\jOOQ-3.8.6).

Code generation config

You need to add jooq config xml file to your project. I added jooq.xml to the root folder.

Run code generator

The simplest way is with bash command, this way will always work, even without any special build tool or IDE.

This script is compatible with git-bash on windows. The libraries and folders are of latest version, change to your specific version before run.

“jooq” script is saved in the “bin” folder which is on the path. Now I can run it from everywhere.

Inside Netbeans, open the terminal and type jooq command, you should be in project root folder, where configuration for jooq is.

Generated code

Jooq will generate code for all your tables. You will find new files in packages with name “*.generated.*” :








Flyway – database migration tool

How to setup migration tool for any IDE

There are many ways how to setup migration tool for a specific project, here I will use a command line approach.

As you already know by now, flyway just runs your SQL files with migration DDL commands.  You create new file for each change, incrementally as your database evolve.

We need a folder where we will put files under the project tree.

File names should follow special naming convention for versioned migrations.

Command “fw”

Because I use bash (cygwin) environment inside Netbeans IDE, i will first enable “flyway” tool as a command inside cygwin bash terminal. I create “fw” command file and put it in the “bin” folder which is on the PATH.

Netbeans project structure

I have simple hello world java web project. I added a resources, db and migrations folders for data migration files:


In root folder, where I will run “fw” command, I added configuration file with the name flyway.conf. This file contain important config settings for flyway to work.

There are many possible settings. You can take prepared flyway.conf file as a base for your configuration file.  Look at conf folder under flyway installation folder, there is sample conf file with comments around every possible configuration key.

Final structure

In simplified view (I omit lot of files here) the structure of a project folder looks like :

Migrations SQL files

This two files are simple migration files:

and second file where we add new field to the table :

Running migrations

There are only few commands. For start, you need only two (info and  migrate). After you write your first migration file, just try out “info” command. You should see pending migration record for your SQL file.

$ fw info

Now you can migrate first file:

$ fw migrate

After adding next SQL file in “migrations” folder you can again try status of current migrations with “info” comand:

You see there is a Pending change from your last migration file. After another “migrate” command, again this migrations will all be marked as “Installed”.

Ok, that’s it ! Migrations are now in full working state !

How to change “current” folder to “project” folder

For successful execution of any flyway command we need to be in proper folder first. The proper folder is folder where flyway.conf file reside. This is project root folder in my example.

Don’t forget to install “TerminalExtras” plugin for Netbeans, then you can just press Alt+. when you staying on the project root node. Change directory (cd) command will be executed inside terminal window and focus will be set to terminal window.




Bash script

How to write bash script

I am using cygwin on windows and I wish to use bash as my primary scripting tool.

Write script file with the special first line which define interpreter. Put file in a folder accessible  from anywhere (folder must be on the PATH). Change file characteristics to be executable (chmod +x).

This script will call notepad++ editor and open file from passed parameters (test.txt).

Unix (LF) – proper line endings

Well, don’t forget (like I was), that cygwin is linux on the windows ! It means , your script files need to be in proper format, as on linux.  If you use console editors as for example “nano”,  it will work automatically, but with notepad++ (windows app), files will be created with windows line endings by default.

2016-11-24-21_30_20-h__home_demo-notepadYou need to change line endings with right click menu … to Unix(LF) , or on the menu /Edit/EOL Conversion/.

2016-11-24-22_16_49-settings Example

2016-11-24-22_25_59-settingsIf you ran demo script and you didn’t get expected “Hello World” but only ” World” maybe, well check your line ending definition.

Want to know more ? Look at this nice little beginners bash tutorial or special hacker web site.