DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Boost your Groovy with NailGun

Boost your Groovy with NailGun

Zemian Deng user avatar by
Zemian Deng
·
Sep. 27, 12 · Interview
Like (0)
Save
Tweet
Share
5.74K Views

Join the DZone community and get the full member experience.

Join For Free

Are you working on a large Hibernate project that takes long time to load up all the hbm.xml files when creating the Session object? This is fine during deployment and runtime because it only loads it once. However, often time we also need to the same Session object to do some ad-hoc HQL queries to debug or validate data. Loading and re-loading large mapping files in a Session to just execute single query is very painful.

Now, I like to poke around Java things with Groovy, and it's a great tool to peek at your data as ad-hoc queries as well. You can easily do this with their groovyConsole GUI tool and add --classpath option to include your project classes. This will bring up a tiny Editor, and you can script to load your hibernate Session there. Once the first run is loaded (the hibenrate Session created), then second run is almost in an instant.

Running the little groovyConsole had wet my appetite, and I was hungry for a better text editor, but yet I don't really want a full blow IDE for scripting. I like do my scripting in a plain editor. Now if you have an editor such as Sublime Text 2 (ST2) that has a "build" feature to execute a external command, then you will enjoy scripting much more. With ST2, I can have it call groovy.bat from inside the editor on the script that I am editing. However, there is another problem: the external command will restart a new JVM process on each run! Now I am back to square one.

To solve this problem, and still have my cake (editor), I recalled an awesome tool called NailGun. This works perfectly with Groovy and my problem. I can start a server like this

java -cp "groovy-all-2.0.1.jar:nailgun-0.7.1.jar" -server com.martiansoftware.nailgun.NGServer

And then in my ST2 editor, I can run an external command like this as the NailGun client:

/path/to/nailgun-0.7.1/ng groovy.ui.GroovyMain test.groovy

Nail gun client sends the script file content to the server and prints the result. Again, after first run, the second run should be instantaneously.

There, I scratched my itch.

Details on how to setup Sublime Text 2 to run NailGun client

  1. Go to menu: "Preference > Browse Packages"
  2. Open the Groovy folder
  3. Save a file named "GroovyNailGunClient.sublime-build" with the following:
       {
         "cmd": ["/path/to/nailgun-0.7.1/ng", "groovy.ui.GroovyMain", "$file"],
         "file_regex": "^(...?):([0-9]):?([0-9]*)",
         "selector": "source.groovy"
       }
    
  4. Select menu "Tool > Build System > GroovyNailGunClient"
  5. Press CTRL+B to run any groovy file in your editor.
Groovy (programming language) Boost (C++ libraries)

Published at DZone with permission of Zemian Deng, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Apache Kafka vs. Memphis.dev
  • Secrets Management
  • DevOps Roadmap for 2022
  • How to Quickly Build an Audio Editor With UI

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: