Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

command line interface - How to compile and run a kotlin file which has dependencies on a jar from CLI?

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(
question from:https://stackoverflow.com/questions/65837625/how-to-compile-and-run-a-kotlin-file-which-has-dependencies-on-a-jar-from-cli

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...