0

I have an application compiled in Java. I build my code through Maven. I want a tag in my project POM, so that if JRE 1.6 is not found in the system, it should not allow my Java application to launch.

Can I get any help with regard to this ?

Harshdip Singh
  • 131
  • 1
  • 2
  • 15
  • Why hard fix on a 1.6 jre? The 1.7 jre should have no problems, and the 1.5 would not run it anyway if it is compiled on 1.6.. – Scorpio Jan 08 '13 at 07:22
  • My java application only supports 1.6 jre due to some other dependency. I want it to function in a way that if the jre version other than 1.6 is picked during launch, it should kill the process. – Harshdip Singh Jan 08 '13 at 07:25
  • The "runtime" configuration inside the POM does not control the execution of your program. It only controls building of a runnable artefact. Once you application is built, it's out of Maven's control. –  Jan 08 '13 at 07:45
  • Any idea if I can bundle the "required execution environment" with the project POM to jre 1.6 ? – Harshdip Singh Jan 08 '13 at 09:22
  • I have both jre 1.6 and jre 1.7. if we build our code with jre 1.6, it gets build. But when we launch it, it launches with jre 1.7. is not there any way where since it gets built by jre 1.6, it should launch with jre 1.6 if it is available ? – Harshdip Singh Jan 08 '13 at 10:18

2 Answers2

0

Perhaps you want to read this:

http://maven.apache.org/enforcer/maven-enforcer-plugin/usage.html

 <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <id>enforce-versions</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireMavenVersion>
                  <version>2.0.6</version>
                </requireMavenVersion>
                **<requireJavaVersion>
                  <version>1.5</version>
                </requireJavaVersion>**
                <requireOS>
                  <family>unix</family>
                </requireOS>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
Lokesh Gupta
  • 463
  • 5
  • 8
  • Thanks for the comment Lokesh. I want to actually find out a way if the application can be stopped from launching if the intended version of JRE is not found in the machine. – Harshdip Singh Jan 08 '13 at 05:18
  • I need to stop the application from being launched at run-time if the JRE picked is not 1.6. Any idea regarding that ? – Harshdip Singh Jan 08 '13 at 05:52
  • This might help you,http://stackoverflow.com/questions/2591083/getting-version-of-java-in-runtime – Lokesh Gupta Jan 09 '13 at 05:27
0

You can run your application as

java -version:1.6 -jar app.jar

it won't start if JRE is not 1.6

or check JRE version programmatically as

public static void main(String[] args) throws Exception {
    if (!System.getProperty("java.version").startsWith("1.6")) {
        throw new IllegalStateException("Illegal JRE version");
    }
}
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • Can I add something in the Project POM so that when I click on the executable, it kills the application if the JRE version used is not 1.6.. ? – Harshdip Singh Jan 08 '13 at 07:21
  • I don't think it's possible, pom is not used at runtime. You can check java version programmatically in your app main as System.getProperty("java.version") and exit it it's not 1.6 – Evgeniy Dorofeev Jan 08 '13 at 07:26
  • Any idea if I can bundle the "required execution environment" with the project POM to jre 1.6 ? – Harshdip Singh Jan 08 '13 at 09:22
  • Only that you can add Java-Version: 1.6 entry to MANIFEST.MF with maven-jar-plugin, but you will have to read it manually – Evgeniy Dorofeev Jan 08 '13 at 09:46
  • One quick question, I have both jre 1.6 and jre 1.7. if we build our code with jre 1.6, it gets build. But when we launch it, it launches with jre 1.7. is not there any way where since it gets built by jre 1.6, it should launch with jre 1.6 if it is available ? – Harshdip Singh Jan 08 '13 at 10:17