Monday, April 22, 2013

32/64 bit issue with SWT, JVM. Solution maven way, eclipse way

SWT ships different libraries for each Operating System (os), Windowing System (ws) and Architecture (arch).
It doesn't allow loading 32 bit library into 64 bit JVM and vice versa.

So one should specify the osgi.arch value explicitly matching the jvm architecture.

In eclipse you can specify from launch configuration -> Arguments -> VM arguments
-Dosgi.arch=x86  for 32 bit jvm
-Dosgi.arch=x86_64 for 64 bit jvm

In maven there is more portable solution via profile
just activate correct profile on system sun.arch.data.model value

<project>
...
<profiles>
...
          <profile>
            <id>osgi-arch-64</id>
            <activation>
                <property>
                    <name>sun.arch.data.model</name>
                    <value>64</value>
                </property>
            </activation>
            <properties>
                <osgi.arch>x86_64</osgi.arch>
            </properties>
        </profile>
      
        <profile>
            <id>osgi-arch-32</id>
            <activation>
                <property>
                    <name>sun.arch.data.model</name>
                    <value>32</value>
                </property>
            </activation>
            <properties>
                <osgi.arch>x86</osgi.arch>
            </properties>
        </profile>
...
</profiles>
...
</project>

In case you are thinking why not setting -Dosgi.arch value in MAVEN_OPTS or JAVA_OPTS?

These are environment variables and they have to be set everywhere you build your project, all your teammates, build servers...



No comments:

Post a Comment