Can not publish Kotlin class files to Tomcat server

Hi friends,

I am developing a web application, using Eclipse + Web Tools Platform + Kotlin plugin.

In the “Web Deployment Assembly” setting, I added the source folder of the Kotlin source files, but when I publish this web app to the Tomcat server, only the *.kt source files are deployed, but the *.class files are not.

Then I added the whole [Kotlin Runtime Libary] to the “Web Deployment Assembly” setting, and try to publish this project, this time I got a “java.io.FileNotFoundException: C:\MyWebApp\kotlin_bin” error.

Now I can not run my web app in Eclipse, because not class files are deployed.

Can anyone help me? Thanks very much!

Hi friends,

I finally solved this problem,
by adding the following setting into the WTP setting file [.settings/org.eclipse.wst.common.component] :

    <wb-resource deploy-path="/WEB-INF/classes" source-path="/kotlin_bin"/>

Now the Kotlin class files will be compiled into virtual folder [/kotlin_bin], and class files in this folder will be deployed into Tomcat Server.

But I think the Kotlin Eclipse plugin should take care of this problem for developers

Hi friends,

In the last post, I said that if I added the [/kotlin_bin] folder into the setting file [.settings/org.eclipse.wst.common.component], the Kotlin class files in the [/kotlin_bin] folder will be deployed into the Tomcat Server

But new problem happened.

The class files in the [/kotlin_bin] folder contain only the class and method declaration information, but the implementation code are not generated in these class files.

So, even these class files are deployed into the Tomcat Server, When I try to start the Tomcat Server, these incomplete class files will cause a java.lang.ClassFormatError with the following error message:

Absent Code attribute in method that is not native or abstract in class file xxxx/xxxx/xxxx

If I run a console app from my project, the kotlin plugin will compile source files and generate class files, then I can copy these class files to the Tomcat Server manually.
But this is very inconvenience because I have to do it over and over again in my development process.

How can I deploy the Kotlin class files of my Web application to the web app server automatically?

Can anyone help me? Thanks very much!

Hi friends, I created an issue for this problem:

https://youtrack.jetbrains.com/issue/KT-14838

Can somebody in the Eclipse plugin development team take a look at this?

1 Like

This issue actually effects WebSphere Liberty publishing as well. The other problem I have is that configuration file in .settings is going to get overwritten by M2E-WTP integration.

In the end I just reverted all the Koltinization to use Java except for the JUnit tests which still work in WebSphere Liberty within Eclipse.

You should change the category to support

1 Like

This is major issue while using Kotlin in Eclipse, Most of my team members use Eclipse for their development,
Because of these build related issues we have to move back to Java

I think Kotlin itself is a very great language, much more better than Java.
Since this issue is a problem about the development tools, but not the language it self,
so I think it may be better if you change the tools, for example, using IntelliJ IDEA, which is made by JetBrains, the same company who made Kotlin language.

IntelliJ IDEA has 2 edition:

the Community edition is free, the Ultimate edition cost money, but you can use it for like 1 month as Free trial.

or, you can consider the EAP edition, it is full functional as the Ultimate edition, and you can use it for free:
https://confluence.jetbrains.com/display/IDEADEV/EAP

Hey,
I agree Kotlin is better language compare to Java, but dev tools are also very important. Eclipse provides much more functionality compare to community addition of Kotlin,
Also we have a team of around 10 people I don’t think it will be feasible for us to buy IDEA Ultimate edition.
IDEA EAP edition is a good choice and we will try to evaluate this.

Thanks for sharing details regarding EAP edition.

By the way, I suggest you to use JetBrains Toolbox.
It can help you to download and update to the latest version of InteliJ IDEA (and many other IDEs)
Also, you can select using EAP edition in the setting dialog.

Hi friends:

I find a workaround. Maybe it can help you.

(1)Create a Kotlin main class, for example:
fun main(args: Array) {
println(“Hello, world!”)
}

(2)Right click this main class, and select “Run”=>“Kotlin Application”
This will make the Kotlin plugin compile all the Kotlin source files, and generate class files.

(3)Deploy your web app to the App server, but use the outputed class folder instead of the source folders.
for example, if the “output folder” of your app is “var/classes”, you can deploy it to the App Server,
like this, in the WTP setting file [.settings/org.eclipse.wst.common.component] :

<wb-resource deploy-path="/WEB-INF/classes" source-path="/var/classes"/>

also you can set this from the Eclipse “Web Deployment Assembly” dialog:

Now, Eclipse WTP plugin will deploy the “var/classes” folder to the app Server, which include all the class files compiled by the Kotlin plugin

Hi everyone

I’ve found a workaround for pushing kotlin class to WTP
Just add this to .settings.org.eclipse.common.component :

<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/kotlin-ic/compile/classes"/>

You wille need to be in incremental build by adding this option to maven:
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>

And eventually to run mvn compile and republish