OneWebSQL and Maven 1.x

OneWebSQL supports Maven 2.x out of box. But a few weeks ago, one of our clients sent us a question: "I don't wanna migrate to Maven 2, do you support Maven 1?" Hm, we thought, the older Maven is retired, it's still in use. Let's see how we can get this done.

As I mentioned, Maven 2.x has "native" support in OneWebSQL. There is a dedicated plugin for it. What about Maven 1.x and other build systems like ant? Well, the OneWebSQL code generator can also be lauched as a standalone Java application. Like any other program, you can run it from the command line, like Eclipse or wherever. If your build system supports running external processes, you've already won. Maven 1.x can run other programs with the <ant:exec> tag. This tag comes from ant, so this solution will work in both systems.

Let's go.

  1. Download OneWebSQL from OneWebSQL.com/download
  2. Unpack the archive file.
    unzip onewebsql-pd2java-1.0.0.zip
    
  3. Make directories in your maven repository:
    mkdir -p ~/.maven/repository/onewebsql/jars/
    
  4. Copy the runtime and generator:
    cp onewebsql-pd2java-1.0.0/onewebsql-*.jar ~/.maven/repository/onewebsql/jars/
    
  5. Copy your license file to your home directory:
    cp /your/download/path/pd2java-license.lic ~/
    
    The temporary license will work too. Just unpack onewebsql-pd2java-1.0.0/lib/license-pd2java-1.0.0.jar.
  6. Add OneWebSQL jars as dependencies to your project. Edit project.xml and add these lines:
    <dependency>
        <groupId>onewebsql</groupId>
        <artifactId>onewebsql-runtime</artifactId>
        <version>1.0.0</version>
        <properties>
            <ear.bundle>true</ear.bundle>
            <jar.manifest.classpath>true</jar.manifest.classpath>
            <ejb.manifest.classpath>true</ejb.manifest.classpath>
            <war.manifest.classpath>true</war.manifest.classpath>
        </properties>
    </dependency>
    
    <dependency>
        <groupId>onewebsql</groupId>
        <artifactId>onewebsql-pd2java</artifactId>
        <version>1.0.0</version>
    </dependency>
    
    
  7. Just before compilation, the OneWebSQL code generator must be launched. Add a pre-goal in maven.xml. Here is entire file:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns:ant="jelly:ant" xmlns:j="jelly:core" xmlns:maven="jelly:maven" xmlns:u="jelly:util">
    
            <preGoal name="java:compile">
                    <attainGoal name="or:generate"/>
                    <ant:path
                            id="or.generate.source.dir"
                            location="${basedir}/target/generated-sources"/>
                    <maven:addPath
                            id="maven.compile.src.set"
                            refid="or.generate.source.dir"/>
            </preGoal>
    
            <goal name="or:generate">
                    <exec executable="java" failonerror="true">
                            <arg value="-jar"/>
                            <arg value="${pom.getDependencyPath('onewebsql:onewebsql-pd2java')}"/>
                            <arg value="-model_sets"/>
                            <arg value="${or_model_files}"/>
                            <arg value="-java_output_dir"/>
                            <arg value="${maven.build.dir}/generated-sources/or"/>
                            <arg value="-java_default_package"/>
                            <arg value="${pom.package}"/>
                            <arg value="-dictionaries_dir"/>
                            <arg value="${or_dictionary_dir}"/>
                            <arg value="-classpath"/>
                            <arg value="${pom.getDependencyPath('onewebsql:onewebsql-runtime')}"/>
                            <arg value="-license_location"/>
                            <arg value="${user.home}/work/onewebsql-pd2java.lic"/>
                    </exec>
            </goal>
    
    </project>
    
    
  8. Save the file. That's all.

Now you're ready to launch Maven 1.x and start developing. Don't forget to launch the eclipse goal so its directory, with the generated code, gets added to the Eclipse build path.

What build system are you using? Share with us in the comments!