use java 7 servlet3.0 in openshift

My openshift app shows deployed successfully but still get 404.

2 reasons:

1 Java compiler version

In my pom file, I first set my compiler plugin version to 1.8. Then i found it is not currently(as of 12/14/2014) supported by openshift. So i put 1.7 there thinking that it would be fine. Turns out openshift uses 1.6 by default. To use 1.7 you have to create a “.openshift/markers/java7” and checkin to your openshift repo.

.openshift and markers are directory, so user mkdir to create them. java7 is just an empty file which could be created by ‘touch java7’.

So in the pom, the compiler plugin could look like:

    <build>
...
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compile.plugin.version}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
  ...
        </plugins>
    </build>
....

    <properties>
        ...
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

The last step would be push to git in openshift.

2 build profile

previously i do not have an openshift build profile, since i saw a root.war i was thinking everything is fine. After i check the size of the war, i found it is not gonna work.

-rw-r–r–. 1 548d1af4e0b8cdd40800017b 548d1af4e0b8cdd40800017b 20461 Dec 14 00:07 ROOT.war

so the build profile is madantory:

    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when
                invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app
                will need. -->
            <!-- By default that is to put the resulting archive into the 'webapps'
                folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <finalName>APP-NM</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>${maven.war.plugin.version}</version>
                        <configuration>
                            <outputDirectory>webapps</outputDirectory>
                            <warName>ROOT</warName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

After this, the war is back:

-rw-r–r–. 1 548d1af4e0b8cdd40800017b 548d1af4e0b8cdd40800017b 5359660 Dec 14 16:34 ROOT.war

Reference is HERE and HERE

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s