Jmockit 0.999.11 does not recognize jdk 8 on windows OS

Our project uses jmockit 0.999.11 for laughing objects for JUnit 4.11 and TestNG 6.9.4 test classes and suites. We use Maven as the mgmt dependency tool and to compile and run these test cases (Windows OS).

We recently migrated our project from JDK 7 to JDK 8 (1.8.0.25). Since then, when I try to execute test cases jmockit gives me an error saying

TestSuite launch

java.lang.IllegalStateException: JMockit requires Java 5 VM or later.

I checked various blogs about this and made sure the classpath has the jmockit jar before the junit jar. Other instructions for adding jdk tools.jar are for Mac OS.

So I can't figure out what else is required for jmockit 0.999.11 to be able to successfully identify JDK 8 (u25). The JMockit ATM upgrade will be our last resort and we would like to avoid it as much as possible.

+3


source to share


1 answer


Long and short - you need to upgrade to a later version of jmockit. When jmockit starts, it uses this block of code in AgentInitialization:

boolean initializeAccordingToJDKVersion() {
   String jarFilePath = discoverPathToJarFile();

   if (Startup.jdk6OrLater) {
      return new JDK6AgentLoader(jarFilePath).loadAgent();
   } else if ("1.5".equals(Startup.javaSpecVersion)) {
      throw new IllegalStateException("JMockit has not been initialized. Check that your Java 5 VM has been started with the -javaagent:" +
            jarFilePath + " command line option.");
   } else {
      throw new IllegalStateException("JMockit requires a Java 5 VM or later.");
   }
}

      

And Startup.jdk6OrLater defines that with:



static final boolean jdk6OrLater = ("1.6".equals(javaSpecVersion)) || ("1.7".equals(javaSpecVersion));

public static boolean isJava6OrLater() {
    return jdk6OrLater;
}

      

You can see the problem. I'll give them the benefit of a doubt of my choice to hard-code versions that are higher than 1.5, but it's disappointing nonetheless.

It looks like 1.8 works with Java 8. There may be earlier versions as well, but 1.8 worked for my cohorts, so I decided to stick with that. Alternatively, switching to Java 7 should do the trick as well.

+1


source







All Articles