There are several ways to do this. The easiest way is to use /usr/bin/open :
/usr/bin/open http://stackoverflow.com/
will open the url in a standard browser or
/usr/bin/open -a Safari http://stackoverflow.com/
will use Safari explicitly.
You can also use AppleScript through the javax.script API (JSR 223), but I don't know the syntax right now.
source share