I wrote this test program to reproduce a problem I am having with Kotlin in Eclipse Oxygen.2 Release (4.7.2). The program works in the IDE but does not work as a run-able jar. Had same problem with Idea 2017.3. Spent hours trying to figure this out. Any help would be appreciated. These are the only two classes in the project. The reason I am using a java main class is that neither IDE will recognize a Kotlin main class when building the jar. And I do have the main class specified in the build configuration. In Eclipse I am using FIle > Export to build a run-able jar.
Windows 8.1x64
h:\KOTPROJECTS\TEST\jar>java -jar test.jar
Testing reveal function
Exception in thread “main” java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file com/edrinx/netfa
xservice/FaxBase
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.edrinx.netfaxservice.AppDriver.main(AppDriver.java:7)
… 5 more
This is the main java class:
package com.edrinx.netfaxservice;
public class AppDriver {
public static void main(String[] args) {
System.out.println("Testing reveal function");
FaxBase.Companion.reveal(false, "Testing reveal function");
}
}
This is the target Kotlin class:
package com.edrinx.netfaxservice
import java.io.File
import java.nio.file.Paths
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatter.BASIC_ISO_DATE
class FaxBase {
companion object {
@JvmStatic fun reveal( pSuccess : Boolean, pMsg : String?) : Boolean{
val tPath : String
val tLog : String
if (pSuccess) {
return pSuccess
}
try {
val currentRelativePath = Paths.get("")
tPath = currentRelativePath.toAbsolutePath().toString()
val localDateTime = LocalDateTime.now()
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
tLog = tPath + "\\NETFAXSVC" + localDateTime.format(BASIC_ISO_DATE) + ".LOG"
File(tLog).appendText(localDateTime.format(formatter) + " " + pMsg + "\r\n")
return pSuccess
} catch (e : Exception){
e.printStackTrace()
return false
}
}
}
}