3

I need to convert Java 1.8 library to 1.6 that uses lambda expression, method references and default methods. I found backport project https://github.com/orfjackal/retrolambda. Project that i need to build uses Maven, I added plugin to pom.xml

<build>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>

  <plugin>
    <groupId>net.orfjackal.retrolambda</groupId>
    <artifactId>retrolambda-maven-plugin</artifactId>
    <version>2.5.1</version>
    <executions>
      <execution>
        <goals>
          <goal>process-main</goal>
          <goal>process-test</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <defaultMethods>true</defaultMethods>
      <target>1.6</target>
    </configuration>
  </plugin>
</plugins>

I build .jar from IntelliJ IDEA -> Build -> Build artifacts. But project still producing Java 1.8 library. I'm new to maven and java, how can i build as java 1.6 library?

EDIT 1 Now project seems to produce correct .jar version, but lib now throwing exception.

Exception in thread "main" java.lang.NoClassDefFoundError: java/nio/file/attribute/FileAttribute
at com.morpherltd.dawg.MReader.<init>(MReader.java:15)
at com.morpherltd.dawg.SingleWordAdjectivizer.<init>(SingleWordAdjectivizer.java:17)
at com.morpherltd.dawg.Adjectivizer.<init>(Adjectivizer.java:4)
at LibTest.main(LibTest.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: 
java.nio.file.attribute.FileAttribute
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 9 more

1 Answers1

0

After adding this plugin to your project pom - execute maven goal from Intelli:

process-main goal will process you main classes;

process-test goal will process test classes.

After goals execution generated artifacts should be available in target/classes directory

Ivan Pronin
  • 1,768
  • 16
  • 14
  • ty now it producing correct version, but now i get an exception when using it. – Sergey Filenko Apr 10 '17 at 21:18
  • java.nio.file package is only available since Java 1.7: https://docs.oracle.com/javase/7/docs/api/java/nio/file/package-summary.html. So, you need to refactor the code using older classes to achieve your goal. – Ivan Pronin Apr 11 '17 at 06:26