3

I have a project with a mixture of Java and Kotlin files. Until recently I've been succesfully compiling it from the command line using a simple script like this:

export CLASSPATH=java/main

# compile Kotlin files
find java/main/ -type d \
| xargs kotlinc-jvm -cp java/lib/google-collections-0.9.jar -d java/main/

# compile Java files
find java/main/ -name '*.java' | xargs javac

Then I started using the JGraphT library, so that created a dependancy on the jgrapht jar. The library is referenced from the Kotlin files. I can still compile my project from IntelliJ, but can't get the command-line script working.

Here's what I have tried:

  1. Add the jar to CLASSPATH. Doesn't work. Kotlin compiler doesn't see it. It probably ignores the CLASSPATH.

  2. Add the jar as another -cp parameter:

    find java/main/ -type d \ | xargs kotlinc-jvm \ -cp java/lib/google-collections-0.9.jar \ java/lib/jgrapht-core-0.9.1.jar \ -d java/main/

Then I get the following error:

error: source entry is not a Kotlin file: java/lib/jgrapht-core-0.9.1.jar

What am I doing wrong?

This is a small hobby project, mainly to play around with Kotlin. That's why I'm not using any build system, such as Ant or Gradle. (Another reason is I don't have any experience with these and they look scary. :))

1 Answer 1

5

As it happens, I managed to find the problem myself immediately after posting the question. The arguments to the -cp parameter have to be separated by a colon (:), not a space. The following works just fine:

find java/main/ -type d \
| xargs kotlinc-jvm \
    -cp java/lib/google-collections-0.9.jar:java/lib/jgrapht-core-0.9.1.jar \
    -d java/main/
Sign up to request clarification or add additional context in comments.

4 Comments

correct, it uses the current operating system path separator.
I'm facing the same but your solution does not seem to work, maybe I misunderstood... I have tried this, before seeing your post kotlinc-jvm ".\src\main.kt" ".\src\myLib.kt" -cp .\bin\selenium\client-combined-3.141.59.jar .\bin\gson-2.8.8.jar -include-runtime -d ".\myApp.jar" and the issue was the same -> 2nd .jar file (gson here) is ignored and compiler outputs "source entry is not a Kotlin file" Changing to kotlinc-jvm ".\src\main.kt" ".\src\myLib.kt" -cp .\bin\selenium\client-combined-3.141.59.jar:.\bin\gson-2.8.8.jar -include-runtime -d ".\myApp.jar" also the 1st is ignored
In Windows: from documentation it seems the ":" has to be change to ";". So, I tried: kotlinc-jvm ".\src\main.kt" ".\src\myLib.kt" -cp ".\bin\selenium\client-combined-3.141.59.jar;.\bin\gson-2.8.8.jar" -include-runtime -d ".\myApp.jar" but exception is like the first attempt's one: "error: source entry is not a Kotlin file: .\bin\gson-2.8.8.jar"
I tried the same in Linux but with ":" instead of ";" as separator, as you did. It works well...so how can I write it in windows terminal? Should I post a new questtion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.