Mar 16, 2012 - Running GlassFish as a service on Windows (Error 1067)

I've been trying to run GlassFish as a service on Windows:

asadmin.bat create-service

Unfortunately, that task didn't show up easy due to one little detail: GlassFish was installed on the famous Program Files folder. Other causes may just need a restart of Windows.

When starting the service, it says: Error 1067: The process terminated unexpectedly. And it really terminates.

Because there is a space character between Program and Files, the path to GlassFish also has spaces. The way GlassFish is called when requested via the service start makes it impossible to resolve the path correctly if there are spaces and other special characters, on Windows.

First of all, make sure you restarted your Windows after installing GlassFish as a service. I also had this problem when not using spaces in the path. After restarting the system, everything got fixed by itself.

Update: The following content, in a gray font, is composed of some workarounds for solving this problem. These workarounds are not required anymore because Byron Nevins just found out the right fix for this problem. Skip to the Solution.

I will not present the perfect solution, but some possible workarounds for this, although I encourage you to share your experiences below in the comments:

1.Just move your whole GlassFish installation to a directory with no spaces behind. It'll just work, no issues.

2.If you really want GlassFish to live in your old directory, you can create a symbolic link to that directory and put it in a legal path.
mklink /d C:\glassfish-3.1.2 C:\"Program Files"\glassfish-3.1.2
Now, create the service using the usual method and still at the old path:
asadmin.bat create-service
And edit the file C:\Program Files\glassfish-3.1.2\glassfish\domains\domain1\bin\domain1Service.xml (assuming base path is C:\Program Files):

• Remove every occurrence of: Program Files\\ or Program Files/, thus making the service executable point to your new symbolic link.

3.Create a service by hand, using sc (don't forget the space before the equal signs):

sc create MyGlassFishServiceName binPath= "C:\Program Files\glassfish-3.1.2\bin\asadmin.bat start-domain domain1" start= auto
This will create a service based on the usual GlassFish administration script, asadmin, so it's not a clean way and some errors may be thrown when manually starting the service. Also, it cannot be stopped. If you just want GlassFish to run as a service at startup, then this probably fits you enough. Update: Thanks to the fellow follower Micael Capitão that pointed out some typos in my command.

The Perfect Way.By editing the file I mentioned above, domain1Service.xml, we should be able to escape the spaces from from the path (usual escaping doesn't seem to work). Also, that could come as default in future versions of the splendid Oracle GlassFish (and the open source edition too, for that matter). Oracle already knows of the problem, like one of the following links reveals. If anybody knows/discovers how this can be achieved, please post in the comments below.

Solution
• After creating the service, edit the file:
C:\Program Files\glassfish-3.1.2\glassfish\domains\domain1\bin\domain1Service.xml
(assuming glassfish is installed at C:\Program Files\glassfish-3.1.2)

• Find the line:
<startargument>C:\\Program Files\\glassfish-3.1.2\\glassfish\\domains</startargument>

• Add double quotes around the path, like this:
<startargument>"C:\\Program Files\\glassfish-3.1.2\\glassfish\\domains"</startargument>

• Do the same for the line:
<stopargument>C:\\app\\big glass\\glassfish\\glassfish\\domains</stopargument>

How do I run GlassFish as a Windows service? (Oracle)
How to create a Windows service by using Sc.exe (Microsoft)

Mar 15, 2012 - Change Jenkins or Hudson HTTP port number

One of the things server administrators of Jenkins or Hudson CI solutions often want to do, is to change the HTTP administration port.

I'll show you how, in 4 different ways: For Windows (service), WAR file deployed in GlassFish, Natively in linux and finally, using wrapper.

It's pretty simple:

For Windows (service installation)
Edit jenkins.xml or hudson.xml
Where is the jenkins.xml or hudson.xml?

Navigate to the directory where you installed Jenkins/Hudson and you will see the XML at the root. Open it and look for tag, there will be all the command arguments to be used when starting up Jenkins or Hudson.

One of those arguments is --httpPort, typically:
--httpPort=8080.
Change 8080 to whatever port number you want.

WAR File, deployed in GlassFish
You will need to change the default HTTP port in GlassFish.

Natively installed in linux
At least for RHEL, you should be able to find the /etc/sysconfig/hudson, which typically has the following line, among other configuration ones:
HUDSON_PORT="8080".
Change 8080 to whatever port number you want.

Other linux distributions (using wrapper)
At the time of writing, Arch Linux's AUR Jenkins version uses wrapper to launch itself from the .war file.

Edit /opt/jenkins/conf/wrapper.conf, find wrapper.app.parameter.2=--httpPort=8070 (typically).
Change 8070 to whatever port number you want.

This wrapper solution applies to any system using wrapper, not only linux.

Forum talk about the Windows version
Configuration tutorial in RHEL

Feb 10, 2012 - Creating KDE's Dolphin services and integrating AES Crypt into it

The main objective of this post is to give you a quick glance at how you can create service menus and plugins for use under Dolphin, the default file manager in KDE.

In order to achieve the goal, you need to know what service you want to create for Dolphin. That's where I present you AES Crypt, a nice simple application that allows you to encrypt/decrypt your files in an easy and cross-platform way. Unfortunately, the linux version lacks some features, like UI integration (for obvious reasons), and it's up to us users to make something about it.

As such, I will show you how to integrate AES Crypt with one specific file manager you can use on Linux, KDE's Dolphin, as I mentioned before. That way, you'll be able to quickly call AES Crypt inside Dolphin, just like the Windows version, no need to pop out the terminal and type aescrypt -e or aescrypt -d everytime.

 Dolphin Preferences, showing the AES service installed.

Let's start then:

Create the service file:

The whole service goes into just one file, and that is the one you will be creating. Create an empty text file and save it with the .desktop extension. The full name I used was aes.desktop.

Define the basic structure:

Like in any other .desktop file, you must define the desktop entry section. You start it with:

[Desktop Entry]

Inside this section, you will put the pairs of keys and values that will tell Dolphin what this .desktop file is all about. However, let's postpone that task for now.

Below the desktop entry line, add the following two lines, which define desktop actions:

[Desktop Action encrypt][Desktop Action decrypt]

The first line will tell Dolphin what to do when you ask it to encrypt a file, the second one will tell it what to do when you want to decrypt a file. You are free to name the actions as you wish. I named them encrypt and decrypt.

The basic structure is done. A desktop entry section and one desktop action section for each atomic thing you want to do. Now you just need to populate these sections with usefulness.

Populate the desktop entry:

Inside this section you will put the pairs of keys and values that will make the file recognizable as a Dolphin service as well as what actions does it offer. The way I'll show you will create an option with a submenu. The submenu will then let you encrypt or decrypt the file you have selected under Dolphin.

So, add the following lines:

Type=Service
This line tells that the desktop file describes a service.

X-KDE-ServiceTypes=KonqPopupMenu/Plugin
This one will make Dolphin know that it must show an option on the context menu with our service.

MimeType=all/all
We want the context menu to appear in all kinds of files, so we set the mime type to everything (all/all).

Icon=kgpg
What icon should our desktop file have. More importantly, what icon will appear in our option of the context menu. I used the kgpg icon that requires having kgpg installed.

Actions=encrypt;decrypt;
This key is crucial because it lists all the actions supported (semicolon separated). The names you gave to the desktop actions before must be the same as the ones you list in this line.

X-KDE-Submenu=AES
Finally, what should be the name of our context menu option? I named it just "AES".

Populate the desktop actions:

For each action you define, you will give a name, an icon (to show in the submenu option) and a command to execute (for calling AES Crypt). So, put the following pairs of keys next to the beginning of encrypt desktop action:

Name=EncryptIcon=kgpg
Here I call the encrypt action "Encrypt" and set the kgpg icon, just like the main context menu option.

Exec=aescrypt -e -p kdialog --password "Insert desired password:" --title "AES Encryption" "%f"
The key Exec is where all the magic happens. When the user selects "Encrypt" in the context menu submenu, the above command will automatically run. What it does is call AES Crypt on the file currently selected ("%f") and encrypt it with a password provided by KDialog. Using KDialog, you can quickly create simple window dialogs to show or input information. The KDialog I used will ask the user for a password, as shown in the picture below:

Now, for the second action (decrypt), it's pretty much the same:
Name=DecryptIcon=kgpgExec=aescrypt -d -p kdialog --password "Provide required password:" --title "AES Decryption" "%f"

Install the plugin:

Now that you have a full service written, it's time for Dolphin to make use of it. To accomplish that, you can either copy the file to ~/.kde4/share/kde4/services/ServiceMenus/ directory (create it if it doesn't exist) or to /usr/share/kde4/services/ServiceMenus/ (create it if it doesn't exist), assuming a typical installation of GNU/Linux. Remember that you should avoid messing with the global directories (like /usr) to maintain your system consistent with your package manager and to avoid sad lucks, so I recommend putting the file in your home. By the way, the tilde (~) represents you home directory.

Give it a try:

Assuming that you have AES Crypt installed as well as KDE, you should now be able to fire up Dolphin, select a file, right click on it, select AES and finally select Encrypt. A KDialog will appear, input your password, and a new file will be created with the name of the non-encrypted plus the .aes extension. Check the contents of the file, you can't understand a thing! It's encrypted. Now go to the AES submenu again and select Decrypt. You will be asked for the password, type it and you will recover the file.

As you can see, creating a service plugin for Dolphin is pretty straightforward and can help ease and fasten some tasks that would be boring otherwise, especially daily ones.

Give AES Crypt a try as it works very flawlessly and is compatible both with Windows, Linux and Mac OS. You can easily secure and move your files from system to system (oh Android and iOS...).

You can download the whole service file: Here.

A few useful links:
AES Crypt