Below you will find pages that utilize the taxonomy term “Java”
Building custom libs that are missing in maven central or jcenter
So you really need that java lib somebody made but they can’t be bothered to upload it to maven central or jcenter? Build it yourself and host it on your nexus repo. That’s what the script below does. Additionally, it includes a little xslt magic which allows to change the pom.xml in any way you want. Are they using snapshot versions? No problem, just insert your own (as shown in the script). Need to change a dependency? With some more xslt you can definitely do that too! You can run this script locally or on a build server (the script is using jenkins’ BUILD_NUMBER environment variable).
Dump all (most?) JMX Beans via Jolokia using just the shell and a bit of json formatting
It seems jolokia doesn’t support dumping everything with just one command.
So here’s a really hacky quick and dirty way to get all information jolokia can access:
for name in $(curl --silent http://dwtest:10002/search/*:* | python -m json.tool | grep '"value":' -A9999 | tail -n +2 | head -n -2 | sed 's/ /%20/g' | cut -d'"' -f2);
do curl --silent "http://dwtest:10002/read/$name" | python -m json.tool;
done
Once you’ve gotten this far, piping the information into a file or another tool is trivial.
Migrating Sonar to a different host
Just a few notes on how to move your sonar installation to another machine without loosing any of your config and/or history. Some of that include the normal installation steps too. This list is specific to debian.
Add the sonar debian repo to your machine (/etc/apt/sources.list.d/sonar)
deb http://downloads.sourceforge.net/project/sonar-pkg/deb binary/
Update and install sonar (sonar pkg is not signed):
aptitude update && aptitude install sonar
Install postgresql and set up an account for your sonar:
To gradle daemon or not to gradle daemon?
The gradle daemon speeds up builds quite a bit and you do want to have it running on your local machine but not on the build server, that one should always re-build from scratch. This is actually quite easy to accomplish.
In your ‘~/.bashrc’ add the following export so your local machine runs all builds with the gradle daemon:
export GRADLE\_OPTS="-Dorg.gradle.daemon=true"
Since, by default, the gradle daemon is not started, it will not be used on your build server.
Tanuki Software's Java Service Wrapper and your Environment Variables
This post has been updated
Here’s an evil little gotcha I ran into when using the Tanuki Software Java Service Wrapper to run our company bamboo server. But first you need to know a little bit of context:
We had our bamboo agent running as root for a long time and about two months ago I changed that. I created a bamboo user and installed multiple agents. Each of these into its own folder along the lines of /home/bamboo/bamboo/java-agent-1
etc. Now in each of these is a wrapper script under bin/bamboo-agent.sh
. Reading up a bit on the wrapper I found out I can change the script and set the variable RUN_AS_USER=bamboo
and then simply create a symlink from /etc/init.d/java-agent-1
to /home/bamboo/bamboo/java-agent-1/bin/bamboo-agent.sh
and then start/stop the service just like any other normal unix service.
Tanuki Software's Java Service Wrapper and your Environment Variables
This post has been updated
Here’s an evil little gotcha I ran into when using the Tanuki Software Java Service Wrapper to run our company bamboo server. But first you need to know a little bit of context:
We had our bamboo agent running as root for a long time and about two months ago I changed that. I created a bamboo user and installed multiple agents. Each of these into its own folder along the lines of /home/bamboo/bamboo/java-agent-1
etc. Now in each of these is a wrapper script under bin/bamboo-agent.sh
. Reading up a bit on the wrapper I found out I can change the script and set the variable RUN_AS_USER=bamboo
and then simply create a symlink from /etc/init.d/java-agent-1
to /home/bamboo/bamboo/java-agent-1/bin/bamboo-agent.sh
and then start/stop the service just like any other normal unix service.
Using WSDLToJava with Gradle
I currently need to generate some java sources from a wsdl with Gradle. In Maven, I’ve done this using the cxf-codegen-plugin but I want to avoid using anything that’s maven in my new build. And there’s several resources out there who will either tell you to call WSDLToJava via cxf’s ant task or directly. The ‘direct’ way still leaves you with several possibilities like calling ProcessBuilder from your Gradle Task or using a JavaExec Task. I went for the last.
Using WSDLToJava with Gradle
I currently need to generate some java sources from a wsdl with Gradle. In Maven, I’ve done this using the cxf-codegen-plugin but I want to avoid using anything that’s maven in my new build. And there’s several resources out there who will either tell you to call WSDLToJava via cxf’s ant task or directly. The ‘direct’ way still leaves you with several possibilities like calling ProcessBuilder from your Gradle Task or using a JavaExec Task. I went for the last.
Anatomy of a Gradle Task: Task Dependencies
Here’s another little “gotcha” on gradle tasks. When they’re triggered. I’ve seen quite a few posts on stackoverflow along the lines of “How can I call a gradle task”. You can’t (Well ok you could but you don’t want to). It is executed as a dependency of another task.
Going back to that little copy task I wanted to execute, I needed it to run roughly somewhere after the clean task and before jar task. I ended up making my copy task dependent of compile. That didn’t work so I tried compileJava and classes and… only to later realize that the dependency was in the wrong direction: My task depends on one that is being executed but that doesn’t trigger my task, it merely states that my task, should it be executed, can only be run after some other task.
Anatomy of a Gradle Task: Task Dependencies
Here’s another little “gotcha” on gradle tasks. When they’re triggered. I’ve seen quite a few posts on stackoverflow along the lines of “How can I call a gradle task”. You can’t (Well ok you could but you don’t want to). It is executed as a dependency of another task.
Going back to that little copy task I wanted to execute, I needed it to run roughly somewhere after the clean task and before jar task. I ended up making my copy task dependent of compile. That didn’t work so I tried compileJava and classes and… only to later realize that the dependency was in the wrong direction: My task depends on one that is being executed but that doesn’t trigger my task, it merely states that my task, should it be executed, can only be run after some other task.
Anatomy of a Gradle Task: Execution Time
So I’m trying out gradle in the hope of being able to simplify and streamline an existing maven build which is quite large and inconsistent. And I just spent some time to figure out a few gotcha about gradle tasks and this post is to help others understand, because I think the gradle docs aren’t clear enough on this point
What I wanted to achieve is, to copy all *.properties files in src/main/java to the resources-output directory so they are included in the jar, because javac won’t pick them up since they’re no java source files. What happened was that, depending on what approach I tried, sometimes the copy worked sometimes it didn’t and I couldn’t understand why.
Anatomy of a Gradle Task: Execution Time
So I’m trying out gradle in the hope of being able to simplify and streamline an existing maven build which is quite large and inconsistent. And I just spent some time to figure out a few gotcha about gradle tasks and this post is to help others understand, because I think the gradle docs aren’t clear enough on this point
What I wanted to achieve is, to copy all *.properties files in src/main/java to the resources-output directory so they are included in the jar, because javac won’t pick them up since they’re no java source files. What happened was that, depending on what approach I tried, sometimes the copy worked sometimes it didn’t and I couldn’t understand why.
Automatically switch your mvn settings
I have one primary development notebook and take that with me wherever I go. Now in a company setting you usually have proxies and whatnot. And I think it’s an official best practice to roll your own company or departement maven proxy/cache.
So dependent on where you are, you might need a different maven ~/.m2/settings.xml file. Here’s a very simple shell function you can add to your ~/.bashrc
function mvn {
MVN="$(which mvn)"
if [ -n "$(ifconfig eth0 | grep YOUR-WORK-IP-HERE)" ]; then
echo ">>> Running mvn whith work config"
${MVN} -gs ${HOME}/.m2/settings-work.xml $*
else
echo ">>> Running mvn with vanilla config"
${MVN} $*
fi
}
This just checks for the ip of eth0 and calls mvn with a special settings.xml. In all other cases mvn is run with the vanilla config (or none, since the settings.xml is optional).
Automatically switch your mvn settings
I have one primary development notebook and take that with me wherever I go. Now in a company setting you usually have proxies and whatnot. And I think it’s an official best practice to roll your own company or departement maven proxy/cache.
So dependent on where you are, you might need a different maven ~/.m2/settings.xml file. Here’s a very simple shell function you can add to your ~/.bashrc
function mvn {
MVN="$(which mvn)"
if [ -n "$(ifconfig eth0 | grep YOUR-WORK-IP-HERE)" ]; then
echo ">>> Running mvn whith work config"
${MVN} -gs ${HOME}/.m2/settings-work.xml $*
else
echo ">>> Running mvn with vanilla config"
${MVN} $*
fi
}
This just checks for the ip of eth0 and calls mvn with a special settings.xml. In all other cases mvn is run with the vanilla config (or none, since the settings.xml is optional).
Accessing Request Parameters in a Grails Domain Class
It’s not exactly elegant to work with request parameters in a domain class but it was necessary. I have a bunch of domain classes with “asMap” methods where they render themself into a map and cascade to other domain objects as needed. In the controller, the resulting map is given to the renderer and we get a nice json response.
So now I’ve changed some fields and in order to stay backwards compatible, I created a new apiKey (a parameter needed for all calls to my app) that distinguishes old and new clients.
Accessing Request Parameters in a Grails Domain Class
It’s not exactly elegant to work with request parameters in a domain class but it was necessary. I have a bunch of domain classes with “asMap” methods where they render themself into a map and cascade to other domain objects as needed. In the controller, the resulting map is given to the renderer and we get a nice json response.
So now I’ve changed some fields and in order to stay backwards compatible, I created a new apiKey (a parameter needed for all calls to my app) that distinguishes old and new clients.
The simplest backup solution ever...
… not for everyone maybe, but for me as a linux/java/groovy person it is!
you’ll need
- java
- groovy
- rsync
- ssh
- cron
I want to regularly copy files from a bunch of paths from several remote hosts to the localhost. I know nothing about arrays etc in bash to configure this stuff in a simple way but the solution I’ve come up with is simple and elegant:
I wrote a little groovy script that generates the shell commands to be executed. the output of the groovy script is piped into bash, which executes the commands. That call of the groovy script with the piping to the bash is in a little shell script which is called from cron.