2

I have a file called A.kt which has dependencies on B.jar. How to compile and run the kotlin file on CLI?

I have tried:

kotlinc A.kt -cp B.jar

but this did not work.

The error I get is:

A.kt:11:24: error: unresolved reference: B
        val b = B(
Vishisht Tiwari
  • 101
  • 1
  • 8

1 Answers1

0

Running kotlinc -help shows:

Usage: kotlinc-jvm <options> <source files>

That puts the options before the source files.  Which is pretty standard: most commands process their arguments in order, so I'd expect the command in the question to compile A.kt before setting up the classpath to include B.jar.

So you should try:

kotlinc -cp B.jar A.kt

Other potential causes include B.jar not being present in the current directory (or not being given along with the necessary path info), and it not containing the relevant .class files (in directories corresponding to their packages).

gidds
  • 16,558
  • 2
  • 19
  • 26
  • Same error with ```kotlinc -cp B.jar A.kt``` – Vishisht Tiwari Jan 22 '21 at 01:09
  • The .jar file works successfully in IntelliJ but I need it to get it working in CLI. The .jar is in the same folder as well and the path I give it correct as well. This is because when I try -verbose in the above command, I do not get any error. On the other hand if I enter the wrong path then I get the following error with verbose: ```warning: classpath entry points to a non-existent location: x/B.jar``` – Vishisht Tiwari Jan 22 '21 at 01:12