Eclipse - How to add Kotlin to a Tomcat Project - Compile Kotlin AND Java Files

試著忘記壹切 提交于 2019-12-04 10:04:54

You need add correspond dependencies. The easiest way to manage project dependencies is to use build tools (maven, gradle, Ant+Ivy...). In maven example you need:

<properties>
    <!-- your properties... and define version fir kotlin -->
    <kotlin.version>1.1.4</kotlin.version>
</properties>

<dependencies>
    <!-- your project dependencies... and add one for kotlin -->

    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jre8</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-test</artifactId>
        <version>${kotlin.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
    <!-- your project plugins... and add one for kotlin -->
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <jvmTarget>1.8</jvmTarget>
            </configuration>
        </plugin>
    </plugins>
</build>

If you use IDE you need to install kotlin language support plugin to make kotlin compile or test run more user friendly.

OK I am narrowing in on this. I found that the kotlin classes are being compiled to this location under runtime lib? Maybe this will be something I can figure to build to my normal classes folder.

OK - To get all the Kotlin menus - turns out you need to be on PACKAGE EXPLORER tab not PROJECT EXPLORER . arggh just found that by fluke.

The creation of a .kt file will automatically add the runtime and libs for Kotlin to your project.

Now on the the issue of the build / compile now. Still outstanding.

OK Update - Downloaded IntelliJ, and "IT" works out of the box, in 15 min I had a Hybrid Java/Kotlin Tomcat Project running.

Still Interested in the Eclipse solution but I am probably just going to shell out the cash for IntelliJ. Time is money.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!