Cygwin, git and ssh: ‘cannot spawn c:cygwinbinssh’

Using Cygwin and git on windows, I ran into an issue where git was working fine in a cygwin shell, but I was trying to setup a Jenkins build accessing a git repo, and git from Windows was giving errors like this:

$ git push myremote master
error: cannot spawn c:cygwinbinssh: No such file or directory
fatal: unable to fork

Running shell commands on Windows in Cygwin this was somewhat misleading, as I wasn’t expecting it to be looking for ‘ssh.exe’.

Turns out my GIT_SSH env var was causing the issue, had to replace this:

GIT_SSH=c:cygwinbinssh

with

GIT_SSH=c:cygwinbinssh.exe

and then all was good.

Using Spring 3.1 Profiles

Profiles in Spring 3.1+ give you the ability to define conditional bean configurations based on a profile name, where one of your defined profiles is selected at runtime based on a selected profile name.

For example, if you have certain beans that are needed for running in a certain deployment environment but not needed for others (dev, test or prod), or if certain beans need to be configured differently between different environments, Profiles give you the ability to do exactly this.

If you’re using XML configuration, you use the profile=”…” attribute on the
<beans> element. For example:

<beans>
    <beans profile="dev">
        ... bean defs for dev profile here
    </beans>

    <beans profile="prod">
        ... bean defs for prod profile here
    </beans>
</beans>

To select your profile at runtime you’ve got a couple of different options – the easiest approach is to declare a system property, or -D parameter to your JVM at startup:

-Dspring.profiles.active=dev

When you initialize your Application Context, Spring automatically checks for this property and then will initialize only the beans declared for that specific profile. Beans not within a profile will still get initialized, or alternatively a profile with the name ‘default’ will get initialized if no other profile is specified.

Another approach if you need more control over the logic to determine which profile is active on startup, you can programmatically select your profile like this:

GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();

if( ... some logic here)
{
    ctx.getEnvironment().setActiveProfiles("example_profile_1");
}
else
{
    ctx.getEnvironment().setActiveProfiles("example_profile_2");
}

ctx.load("classpath:applicationContext.xml");
ctx.refresh();

Notice with this approach, since we’re not using the spring.profiles.active property, we don’t want to load the context xml file until after we’re determined programmatically which profile is active (based on some logic), then we set the profile with setActiveProfiles(), then load the xml, and refresh the context to initialize our beans for the selected profile.

Resetting a password on Ubuntu

If you’ve forgot your user password on Ubuntu, you can easily reset it if you have a recovery option in your Grub menu. Boot into recovery mode, select the root shell option, then use passwd to set a new password for your user. Further details here.

If you get this error:

Authentication token manipulation error

then your drive is mounted in read only mode. If you have an option in your recovery menu to mount in r/w mode, then do that first then drop back into the shell. Otherwise you can mount it yourself with this:

mount -rw -o remount /

More info here.

Forge app error “No mime type could be found for file favicon.ico”

Apps generated using JBoss Forge get this error showing up in the server log:

JSF1091: No mime type could be found for file favicon.ico.  To resolve this, add a mime-type mapping to the applications web.xml

This is described in this bug: https://issues.jboss.org/browse/FORGE-657

The quick fix is to add this to your web.xml:

<mime-mapping>
   <extension>ico</extension>
   <mime-type>image/x-icon</mime-type>
</mime-mapping>