# How to make standalone kotlin apps with gradle?

**URL:** <https://discuss.kotlinlang.org/t/how-to-make-standalone-kotlin-apps-with-gradle/4982>\
**Category:** Support\
**Created:** [October 13, 2017, 2:12pm UTC](https://discuss.kotlinlang.org/t/how-to-make-standalone-kotlin-apps-with-gradle/4982 "2017-10-13T14:12:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avraneel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/avraneel/32/4207_2.png) [@Avraneel](https://discuss.kotlinlang.org/u/Avraneel)\
**Post date:** [October 13, 2017, 2:12pm UTC](https://discuss.kotlinlang.org/t/how-to-make-standalone-kotlin-apps-with-gradle/4982/1 "2017-10-13T14:12:32Z")

</div>

I tried to make a simple “Hello World” kotlin app, with all dependencies stored within it.  
Heres the code:

> package com.neel.helloworld  
> fun main(args: Array) {  
> var str: String = “Hello world”  
> var name: String = “Neel”  
> str = str + " from " + name  
> println(str)  
> println(“whats up?”)  
> }

This is my gradle script:

> buildscript {  
> ext.kotlin\_version = ‘1.1.51’  
> repositories {  
> mavenCentral()  
> }  
> dependencies {  
> classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin\_version”  
> }  
> }  
> apply plugin: ‘kotlin’  
> apply plugin: ‘application’  
> mainClassName = ‘com.neel.helloworld.HelloKt’  
> defaultTasks ‘run’  
> repositories {  
> mavenCentral()  
> }  
> dependencies {  
> compile “org.jetbrains.kotlin:kotlin-stdlib:$kotlin\_version”  
> testCompile ‘junit:junit:4.11’  
> testCompile “org.jetbrains.kotlin:kotlin-test-junit:$kotlin\_version”  
> }  
> jar {  
> manifest {  
> attributes ‘Main-Class’: ‘com.neel.helloworld.HelloKt’  
> }  
> //NEWLINE  
> from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }  
> }

What i get is an error hen i try to run the resultant jar file which is at /projectroot/build/lib/. The error is:

$java -jar HelloWorld2.jar  
Error: Could not find or load main class com.neel.helloworld.HelloKt

I forgot to mention but the name of the file is Hello.kt.  
This i tried to build with this command:  
$gradle jar

Is my gradle file wrong,and where so? Pls help.

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [October 16, 2017, 8:59pm UTC](https://discuss.kotlinlang.org/t/how-to-make-standalone-kotlin-apps-with-gradle/4982/2 "2017-10-16T20:59:24Z")

</div>

Your Jar file is just a zip file with a different extension. Have a look at it. What class files are contained in the Jar?

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [October 17, 2017, 5:15am UTC](https://discuss.kotlinlang.org/t/how-to-make-standalone-kotlin-apps-with-gradle/4982/3 "2017-10-17T05:15:38Z")

</div>

The most probable explanation is that you assigned package but did not place your `Hello.kt` into appropriate directory. JVM expects class file with name `com.neel.helloworld.HelloKt` to be in `com/neel/helloworld` directory relative to classpath root.
