Bash script: Recursively convert line breaks in all files from Dos/Windows to Unix AND Replace Tabs with Spaces.

It’s really annoying that on Windows, nearly every program that deals with text saves the text in Windows-format. That’s not good when you work in a multi-OS-environment.
Another annoying thing are TABS, which often are much wider in Linux editors than in Windows, and are generally superflous as i think. Especially when programming Scala, where the style guide suggests using spaces instead of tabs.

So today i ended my misery with converting text-files and tabs by hand and finally wrote a Bash script. It works both on Linux and on Cygwin.

It solves both problems at once: It converts Windows CR/LF line breaks (only when there is one!), AND replaces those superflous tabs with spaces. And all that with one single line.

Read More »

Posted in General | Tagged , | Leave a comment

Get Weld project running in Glassfish Tools Bundle for Eclipse 1.2

Today i took a look into the GlassFish Tools Bundle for Eclipse to see if it could speed up my Java EE6-development. I was especially  curious about the hot-deployment capabilities.

After downloading the Glassfish Tools from the download site and importing a simple Weld-JEE-project (i was using the Maven archetype “weld-jsf-jee-archetype”), an error showed up, pointing to the beans.xml of my project and saying

Referenced file contains errors (jar:file:/D:/Program Files (x86)/GlassFish-Tools-Bundle-For-Eclipse-1.2/dropins/feature-1.0.50/eclipse/plugins/com.sun.enterprise.jst.server.sunappsrv_1.0.50.jar!/ee6_schemas/beans_1_0.xsd).

So i opened the file com.sun.enterprise.jst.server.sunappsrv_1.0.50.jar in the mentioned directory with an archiver, where i found the beans_1_0.xsd in the folder ee6_schemas, which i opened with a text editor.

The targetNamespace of the schema file was pointing to the Seamframework, which sounded strange to me. So i googled to find another beans_1_0.xsd schema file and found one in the Weld trunk, with the targetNamespace=”http://java.sun.com/xml/ns/javaee” – which sounded much better to me.

So i replaced the schema file in the archive with the one from the Weld repo (you have to shutdown the GlassFish Tools Bundle first) and restarted the bundle, made a clean of my project  – and voilà, the error vanished!

[EDIT]
I switched back to Eclipse and downloaded the Glassfish adapter seperately. Seems to work faster and more stable to me.

Also, there are some really annoying issues when deploying a Maven JEE6-app on Glassfish within Eclipse (both in bundled and non-bundle version with GF3 adapter). When “enable dependency management” in M2Eclipse is enabled, i can’t deploy the project. When it’s disabled, deploying works – but programming is hard because of the missing dependencies (although it works somehow).
Will write an article about that issue soon…

Posted in General | Tagged , , | Leave a comment

Enable Weld Logging on Glassfish with Maven

Just figured out how to use a Weld-injected Logger on Glassfish.
Unfortunately, i couldn’t get Log4J12 as SL4J Implementation running, like the author of this post did (i hope i’ll find out later), but with the sl4j-jdk14 binding, the logging just works.

Steps:

  1. Add the following dependencies to the pom.xml:
<!-- SL4J API -->
 <dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-api</artifactId>
 <version>1.6.0</version>
 </dependency>

 <!-- SLF4J JDK14 Binding  -->
 <dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-jdk14</artifactId>
 <version>1.6.0</version>
 </dependency>

 <!-- Injectable Weld-Logger -->
 <dependency>
 <groupId>org.jboss.weld</groupId>
 <artifactId>weld-logger</artifactId>
 <version>1.0.0-CR2</version>
 </dependency>

2. Inject the Logger and use it as usual:

import javax.inject.Inject;
import org.slf4j.Logger;

public class Example {
  @Inject
  private Logger logger;

  public void exampleFunc() {
    logger.info("Hello Logger!");
  }
}
Posted in General | Tagged , | 2 Comments

Use Ant-Contrib Tasks in Maven

I just messed around a while to get a simple Ant-contrib task running inside a Maven build – a simple <if>.
The examples on the net weren’t very helpful or too bloated, so i’ll post a very simple one.

The problem with Ant-contrib is that this library doesn’t come with the regular Ant-distribution. So it has to be downloaded separately.
But inside the Maven-antrun-plugin, Ant can’t access the ant-contrib.jar without explicitely referencing it with a hard-coded path (for example classpath=”C:/Dev/Ant/ant-contrib-1.0b3.jar”) – although it’s in the system classpath.

As it’s not the best practice to refer to local filesystem dependencies and rather downloading and using them within the Maven lifecycle, i’m referencing the ant-contrib.jar that Maven downloads when resolving the dependencies.

In my example i’m checking if the environment variable GLASSFISH has been set, failing the complete build if it’s not.
So my pom.xml looks like this: Read More »

Posted in General | Tagged , | Leave a comment

Batch script: Convert long folder name to short 8.3 name

When running Windows, i often had problems with long folder-names, especially on the command line.
Since Scala also has a problem with a JDK lying in a folder like “Program Files(x86)” i decided to write a little batch-helper to convert long folder names to the short 8.3-form.
Then i put the short name of my JDK folder into my environment variables, voilà – i don’t need to move the JDK to satisfy Scalas needs ;)
The script works like this:

C:\>83conv C:\Program Files (x86)\Java\jdk1.6.0_20
C:\PROGRA~2\Java\JDK16~1.0_2

C:\>

The source:
Read More »

Posted in General | Tagged , | 1 Comment

Programmer approaching

And now for something completely different:

No, i wasn’t the pilot. Not yet ;)

Posted in General | Leave a comment

Maven & Scala: Add source folder to Eclipse Project

Just solved one another annoying problem:
Everytime i had to clean my maven-eclipse-project with “mvn eclipse:clean” and re-created the project, i had to manually re-add the “src/test/scala”-folder to the eclipse project.
Now i found a way to tell maven additional source folders to integrate into the eclipse project: the build-helper-plugin.

So to add my src/test/scala-folder permanently i added the following plugin-configuration to my pom.xml (i also had to add the source) :

<!-- ================== MAVEN BUILDER PLUGIN =================== -->
<plugins>
(...)
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.1</version>
  <executions>
    <execution>
      <id>add-source</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>add-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>src/main/scala</source>
        </sources>
      </configuration>
    </execution>
    <execution>
      <id>add-test-source</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>add-test-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>src/test/scala</source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>
(...)
</plugins>

Wonderful plugin. You can add infinite source folders to your project.
I will surely need it again, when i’m adding the next programming language to my project :-D

Posted in General | Tagged , , | 1 Comment

Maven Scala Build Error “error while loading Function1, class file needed by Function1 is missing”

Scala and Maven… a kinda’ fragile combination ;)
Today i got the following error when trying to compile my scala-project with “mvn compile”:

[ERROR] error: error while loading Function1, class file needed by Function1 is missing.
[INFO] reference value Unit of package scala refers to nonexisting symbol.
[ERROR] one error found
[INFO] ————————————————————————
[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1(Exit value: 1)

Nothing worked anymore – no compiling, cleaning, testing or anything else concerning scala and maven.
My solution: Delete all scala-folders/files in your Maven Repository (%USER%/.M2), so that maven re-downloads them.
After that, anything worked again for me.

Posted in General | Tagged , | Leave a comment

Build a mixed Scala 2.8/Java application from scratch with Maven [Eclipse Settings]

Now i’m going to show you how to open the Maven project from Part 1 with Eclipse and what you have to care about when developing Scala/Java/Maven within Eclipse. It’s very easy to setup, but it took me a while so maybe it helps someone out there.
I’m using Eclipse version 3.5.2.

Before opening the Maven project with Eclipse, we need to download the M2Eclipse plugin and do some other adjustments to eclipse. M2Eclipse will handle all dependencies for our project and will build it automatically.

You can get the M2Eclipse-plugin from this update site:
http://m2eclipse.sonatype.org/sites/m2e
M2eclipse needs Eclipse to use the JDK as the JVM (the default setting is the JRE), so you have to alter the Eclipse.ini, inserting the path to your JDK.
Insert your JDK path before the vmargs. My Eclipse.ini looks like this:

Read More »

Posted in General | Tagged , , , | 2 Comments

Build a mixed Scala 2.8/Java application from scratch with Maven

In this tutorial I will show you how to build an application by Maven that consists of Java and Scala source files. The project automatically uses the latest Scala 2.8-Snapshot until it’s released (Maven will look for the latest version of the Scala language each time you build it).
We will setup the project to use cross-compiling, so the java-classes can access Scala-classes and vice versa.

The good thing about maven projects is that you don’t need an IDE to start a project, thus remaining independent from certain IDE-features. In my next article, i will show how to configure eclipse to open the maven project. But for now i’ll show how to create the project from command line only.

If you’re impatient and just want to see the resulting pom.xml, you can also download the complete source:
Complete maven project

Read More »

Posted in General | Tagged , , | 13 Comments