Can't Run Hello World program in Tornadofx - kotlin

I'm using Ubuntu Mate 16.04 and I'm trying to run a simple hello world program using tornadofx. The file is called hello.kt and I'm attempting to compile and run it using just the terminal.
It seems to compile just fine by running
kotlinc -cp tornadofx.jar hello.kt -include-runtime -d hello.jar
But when I try to run it by entering
java -jar hello.jar
I get a NoClassDefFoundError error:
Exception in thread "main" java.lang.NoClassDefFoundError: tornadofx/View
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at HelloKt.main(hello.kt:15)
Caused by: java.lang.ClassNotFoundException: tornadofx.View
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Here's the file:
import javafx.scene.control.Label
import javafx.scene.layout.HBox
import tornadofx.App
import tornadofx.View
class HelloWorld : View() {
override val root = HBox(Label("Hello world!"))
}
class HelloWorldApp : App() {
override val primaryView = HelloWorld::class
}
fun main(args: Array<String>) {
val window = HelloWorldApp()
}
Any help would be greatly appreciated. Thanks.

You need to install Oracle JDK, which comes with JavaFX, or install the JavaFX OpenJDK bundles in Ubuntu. I would recommend the Oracle JDK.
Additionally, JavaFX Applications has to be launched, you can't simply instantiate the App class. See below.
The syntax in your example code is very outdated - did you find this in the guide or somewhere else? This is the current syntax for your code example, including the correct launch command.
class HelloWorld : View() {
override val root = hbox(label("Hello world!"))
}
class HelloWorldApp : App(HelloWorld::class)
fun main(args: Array<String>) {
launch<HelloWorldApp>(args)
}

Related

Kotlin in VS Code - Unresolved reference for user defined class in another file

I'm trying to set up Kotlin for VS Code following the instructions in this article, which basically says to install the Kotlin and Code Runner extensions.
So far, so good, I am able to run the following code:
App.kt:
fun main() {
MyApp().printTest()
}
class MyApp {
fun printTest() {
println("Hello test")
}
}
However, when I try to extract the MyApp class to another file in the same folder, I can't import it:
App.kt:
import MyApp.MyApp // import MyApp doesn't work also
fun main() {
MyApp().printTest()
}
MyApp.kt:
class MyApp {
fun printTest() {
println("Hello test")
}
}
I've tried to import the Java Import Snippets extension, but it doesn't work, showing a unresolved reference for MyApp.
Am I missing some extension or VS Code configuration?
That's the command VS Code is running:
cd ".../testapp/src/" && kotlinc App.kt -include-runtime -d App.jar && java -jar App.jar
Should it reference MyApp.kt somehow?
Note: I'm on Debian.
You have no project's package name defined.
Put the files App.kt and MyApp.kt in the same folder level.
In App.kt, only use
import MyApp // or no import at all,
fun main() {
MyApp().printTest()
}
Read more about Java/Kotlin package

Loading a Kotlin main class from a Gradle Fat Jar fails

Based on other answers here I am using this Gradle build to create a fat/uber/shaded Jar with my command line tool and a number of JDBC drivers:
import org.gradle.jvm.tasks.Jar
dependencies {
api(project(":db2xls"))
api("ch.qos.logback:logback-classic:1.2.3")
api("com.h2database:h2:1.4.200")
api("org.postgresql:postgresql:42.2.16")
api("mysql:mysql-connector-java:8.0.21")
api("com.microsoft.sqlserver:mssql-jdbc:8.4.1.jre11")
}
val fatJar = task("fatJar", type = Jar::class) {
manifest {
attributes["Implementation-Title"] = "DB2XLS Bundle"
attributes["Implementation-Version"] = "0.1-SNAPSHOT"
attributes["Main-Class"] = "de.peterbecker.xls.Db2XlsKt"
}
from(
configurations.compile.get().map { if (it.isDirectory) it else zipTree(it) },
configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }
)
with(tasks.jar.get() as CopySpec)
}
tasks {
"build" {
dependsOn(fatJar)
}
}
The build produces a JAR file that looks ok when inspecting with a ZIP tool, but it fails to execute:
$ java -jar db2xls-bundle-0.1-SNAPSHOT.jar
Error: Could not find or load main class de.peterbecker.xls.Db2XlsKt
Caused by: java.lang.ClassNotFoundException: de.peterbecker.xls.Db2XlsKt
The same goes if I use a classpath instead:
$ java -cp db2xls-bundle-0.1-SNAPSHOT.jar de.peterbecker.xls.Db2XlsKt
Error: Could not find or load main class de.peterbecker.xls.Db2XlsKt
Caused by: java.lang.ClassNotFoundException: de.peterbecker.xls.Db2XlsKt
The class file seems to be there, though:
$ jar -t --file db2xls-bundle-0.1-SNAPSHOT.jar | grep Db2XlsKt
de/peterbecker/xls/Db2XlsKt$logger$1.class
de/peterbecker/xls/Db2XlsKt$processQuery$1.class
de/peterbecker/xls/Db2XlsKt$toLists$$inlined$use$lambda$1.class
de/peterbecker/xls/Db2XlsKt.class
And the normal JAR seems to find load the class as expected (then failing on the lack of a depdency):
$ java -cp db2xls-0.1-SNAPSHOT.jar de.peterbecker.xls.Db2XlsKt
Error: Unable to initialize main class de.peterbecker.xls.Db2XlsKt
Caused by: java.lang.NoClassDefFoundError: kotlin/NoWhenBranchMatchedException
What am I doing wrong?
The full code is available at https://github.com/peterbecker/xls-utils/tree/fat_jar

kotlin fun main(args : Array<String>) doesn't work in command line

In Kotlin 1.3.30 I just installed, the main entry function doesn't work in command line. JDK is version 8. Intellij Idea is 2019.1.1. No dependency, very clean project.
When I started learning Kotlin, the main entry is 'fun main(args: Array)'. Last year, 'fun main()' could be used without 'args' and I used it a lot.
Now I have a project needs command line parameters, but something goes wrong. I've tried 3 formats:
// 1. doesn't work.
fun main(vararg args: String){
println("this is a test.")
}
// 2. doesn't work
fun main(args: Array<String>){
println("this is a test.")
}
// 3. this works. but where can I get the command line parameters?
fun main(){
println("this is a test.")
}
1 & 2 has same response:
λ java -jar test-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at com.yxy.ProgramFileKt.main(ProgramFile.kt)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
It works fine with 3 without changing any other thing. But I need command line args.
Judging by the exception, your jar does not contain the Kotlin stdlib. You need to slightly modify your build.
Adding something like this to your Gradle build should fix it:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.0"
}
P.S. This error is very common and has little to do with the main function. Try googling the error message.

Micronaut 1.0 RC1 does not run in IntelliJ

I have created a blank app using Micronaut 1.0.RC1 and CLI command
mn create-app sillynaut --profile service \
--features java,spock,jdbc-hikari,hibernate-jpa,jib
After importing the project into IntelliJ 2018.2.4 I tried to start the Application by running the main method of the Application class.
/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java "-javaagent:/Users/saw303/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/182.4505.22/IntelliJ IDEA 2018.2 EAP.app/Contents/lib/idea_rt.jar=58014:/Users/saw303/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/182.4505.22/IntelliJ IDEA 2018.2 EAP.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/tools.jar:/Users/saw303/dev/private/sillynaut/out/production/classes:/Users/saw303/dev/private/sillynaut/out/production/resources:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/http-client/1.0.0.RC1/e0fc1145ac279e2cb37ba83588de3c0deb7f5562/http-client-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut.configuration/hibernate-jpa/1.0.0.RC1/5f7482f9c8dfde45d9c0e5ddfb743af22e9ccc64/hibernate-jpa-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut.configuration/hibernate-validator/1.0.0.RC1/505c233c19409a644fd519308741a020610c8755/hibernate-validator-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/validation/1.0.0.RC1/9f489bc12364c0a5b647e7538f8be830f7849bdb/validation-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/http-server-netty/1.0.0.RC1/20bfb981de34fc9b32aae83b7141ac8b139c673b/http-server-netty-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/http-server/1.0.0.RC1/8c1d1b42691a41e81a006049a363ff29014ce8cb/http-server-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/runtime/1.0.0.RC1/f9fa101c607f9fcb77c4b4d761873002d28edff3/runtime-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut.configuration/jdbc-hikari/1.0.0.RC1/1ce15a9884df1887301adf12e484722cf332c5c1/jdbc-hikari-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/http-netty/1.0.0.RC1/ca6338005bda1be53f0b502ae43ce7be708beab0/http-netty-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/websocket/1.0.0.RC1/e36ee91ebd54fca37b04abd12b724aaa54e0e82d/websocket-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/router/1.0.0.RC1/b6d9b9788c8c7aa6d6574765b4025478ada0a21f/router-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/http/1.0.0.RC1/594776dec6ea851bf0991586f68a642dfe327cfe/http-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/spring/1.0.0.RC1/a690ca8cdc8171c0951ae361329a105b2297e0cf/spring-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/aop/1.0.0.RC1/de6aacbc752eb66d16cb55f67e82136802c397a6/aop-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/jdbc/1.0.0.RC1/38ba150513d5e2cc8b480d6f21cc46b339acbdc2/jdbc-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/javax.annotation/javax.annotation-api/1.3.2/934c04d3cfef185a8008e7bf34331b79730a9d43/javax.annotation-api-1.3.2.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.micronaut/buffer-netty/1.0.0.RC1/52d8abe4b92041ec14028e1523c02cb917943b48/buffer-netty-1.0.0.RC1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.mariadb.jdbc/mariadb-java-client/2.2.5/3d1406a8ed02ca69cc389ae715cee8913871a81e/mariadb-java-client-2.2.5.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.zaxxer/HikariCP/2.7.9/a83113d2c091d0d0f853dad3217bd7df3beb6ae3/HikariCP-2.7.9.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.25/da76ca59f6a57ee3102f8f9bd9cee742973efa8a/slf4j-api-1.7.25.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.2.2/db2277cb0641bd8bd2f491fab555d37345351d6/rxjava-2.2.2.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-handler-proxy/4.1.29.Final/67e9473ac043b4d173ac9d620d43eb428ecc408a/netty-handler-proxy-4.1.29.Final.jar:/Users/saw303/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/1.23/ec62d74fe50689c28c0ff5b35d3aebcaa8b5be68/snakeyaml-1.23.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.hibernate.validator/hibernate-validator/6.0.13.Final/af4232bf90ecd33c71147d67185dbb1cfe8f33df/hibernate-validator-6.0.13.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/javax.validation/validation-api/2.0.1.Final/cb855558e6271b1b32e716d24cb85c7f583ce09e/validation-api-2.0.1.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.9.7/98d8f190db07f97c64c0ea3af5792f718a6c2cc1/jackson-datatype-jdk8-2.9.7.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.9.7/cbd919f1ce67533e07b98dd493247e8dbabc26b2/jackson-datatype-jsr310-2.9.7.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.9.7/e6faad47abd3179666e89068485a1b88a195ceb7/jackson-databind-2.9.7.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-core/5.3.6.Final/42c7130757c3f67dda008d8edb28b381a09a7ce6/hibernate-core-5.3.6.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/5.0.8.RELEASE/4da63072d1ed6a2eb4bc0a4c8da5e09f39b5021e/spring-orm-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.reactivestreams/reactive-streams/1.0.1/1b1c911686eb40179219466e6a59b634b9d7a748/reactive-streams-1.0.1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-codec-http/4.1.29.Final/454688b88cea27a4d407202d1fc79a6522345b5e/netty-codec-http-4.1.29.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-handler/4.1.29.Final/1acf1d94799296a2517533ec75ce7e155e9c4ea7/netty-handler-4.1.29.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-codec-socks/4.1.29.Final/f687150259de44f0ff7b37a449f1a1bf6f20e992/netty-codec-socks-4.1.29.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-core/1.2.3/864344400c3d4d92dfeb0a305dc87d953677c03c/logback-core-1.2.3.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-codec/4.1.29.Final/1651bc2e279216773c234cafe402d68d2a5adc90/netty-codec-4.1.29.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-transport/4.1.29.Final/c190b90f70e2ae8a48c068afad709e8728fcaa39/netty-transport-4.1.29.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/3.0.2/25ea2e8b0c338a877313bd4672d3fe056ea78f0d/jsr305-3.0.2.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.9.0/7c10d545325e3a6e72e06381afe469fd40eb701/jackson-annotations-2.9.0.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.9.7/4b7f0e0dc527fab032e9800ed231080fdc3ac015/jackson-core-2.9.7.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.hibernate.common/hibernate-commons-annotations/5.0.4.Final/965a18fdf939ee75e41f7918532d37b3a8350535/hibernate-commons-annotations-5.0.4.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.jboss.logging/jboss-logging/3.3.2.Final/3789d00e859632e6c6206adc0c71625559e6e3b0/jboss-logging-3.3.2.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/javax.persistence/javax.persistence-api/2.2/25665ac8c0b62f50e6488173233239120fc52c96/javax.persistence-api-2.2.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.23.1-GA/c072c13dcb7f705471c40bafb1536171df850ab2/javassist-3.23.1-GA.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy/1.8.17/9a36bc0f6eb9f941da0526ad89c4fb4b8ab580f0/byte-buddy-1.8.17.jar:/Users/saw303/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.jboss.spec.javax.transaction/jboss-transaction-api_1.2_spec/1.1.1.Final/a8485cab9484dda36e9a8c319e76b5cc18797b58/jboss-transaction-api_1.2_spec-1.1.1.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.jboss/jandex/2.0.5.Final/7060f67764565b9ee9d467e3ed0cb8a9c601b23a/jandex-2.0.5.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/com.fasterxml/classmate/1.3.4/3d5f48f10bbe4eb7bd862f10c0583be2e0053c6/classmate-1.3.4.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/javax.activation/javax.activation-api/1.2.0/85262acf3ca9816f9537ca47d5adeabaead7cb16/javax.activation-api-1.2.0.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/dom4j/dom4j/1.6.1/5d3ccc056b6f056dbf0dddfdf43894b9065a8f94/dom4j-1.6.1.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/5.0.8.RELEASE/efcf5f0ccaaa9deec2d9133c9d6bfbb7e55370ff/spring-jdbc-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.0.8.RELEASE/b6488db6192f71bd682a13b9d42127307631c616/spring-tx-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/5.0.8.RELEASE/3a067d8990761111c9b6d1d895640be26cc1fb38/spring-context-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aop/5.0.8.RELEASE/f5086c1a3185c481104511837427b39a07a57aa2/spring-aop-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.0.8.RELEASE/5fc965d3e7f5515099244857a8ae9e2a208c169b/spring-beans-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-expression/5.0.8.RELEASE/f23158f22c917df2cddf2ecebc398a9e95f95fae/spring-expression-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.0.8.RELEASE/dc39c49e3246cdf73d3786ac41119140aed3fa08/spring-core-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.glassfish/javax.el/3.0.1-b08/8fa39d3901fc6ec8c0fff4ad4e48c26c4911c422/javax.el-3.0.1-b08.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-buffer/4.1.29.Final/c3809f72e4b535b343b7dfa3c0c8210dad2fa5ea/netty-buffer-4.1.29.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-resolver/4.1.29.Final/bbec1dc913732e4773893c14d795b15d6c1e878e/netty-resolver-4.1.29.Final.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.0.8.RELEASE/a1fa8fb560fb252321776e16bc9ac8201af4ef5e/spring-jcl-5.0.8.RELEASE.jar:/Users/saw303/.gradle/caches/modules-2/files-2.1/io.netty/netty-common/4.1.29.Final/a5d6a735ed07d8f197daa48db7f097cfc971ee5e/netty-common-4.1.29.Final.jar sillynaut.Application
Exception in thread "main" java.lang.NoClassDefFoundError: io/micronaut/context/ApplicationContextBuilder
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sillynaut.Application.main(Application.java:8)
Caused by: java.lang.ClassNotFoundException: io.micronaut.context.ApplicationContextBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Running it with from the console using ./gradlew run works fine.
This is the content of build.gradle:
plugins {
id "io.spring.dependency-management" version "1.0.6.RELEASE"
id "com.github.johnrengelman.shadow" version "4.0.0"
id "net.ltgt.apt-eclipse" version "0.18"
id "net.ltgt.apt-idea" version "0.18"
id "com.google.cloud.tools.jib" version "0.9.9"
}
apply plugin:"application"
apply plugin:"java"
apply plugin:"groovy"
version "0.1"
group "sillynaut"
repositories {
mavenLocal()
mavenCentral()
maven { url "https://jcenter.bintray.com" }
}
dependencyManagement {
imports {
mavenBom 'io.micronaut:bom:1.0.0.RC1'
}
}
dependencies {
annotationProcessor "io.micronaut:inject-java"
annotationProcessor "io.micronaut:validation"
annotationProcessor "javax.persistence:javax.persistence-api:2.2"
implementation "io.micronaut:http-client"
implementation "io.micronaut:inject"
implementation "io.micronaut:validation"
implementation "io.micronaut:runtime"
implementation "io.micronaut.configuration:jdbc-hikari"
implementation "io.micronaut.configuration:hibernate-jpa"
implementation "io.micronaut:http-server-netty"
implementation "javax.annotation:javax.annotation-api:1.3.2"
compileOnly "io.micronaut:inject-java"
runtimeOnly "ch.qos.logback:logback-classic:1.2.3"
testImplementation("org.spockframework:spock-core:1.2-groovy-2.4") {
exclude group: "org.codehaus.groovy", module: "groovy-all"
}
testImplementation "io.micronaut:inject-groovy"
testImplementation "junit:junit:4.12"
testImplementation "io.micronaut:inject-java"
testImplementation "org.hamcrest:hamcrest-all:1.3"
runtime 'org.mariadb.jdbc:mariadb-java-client:2.2.5'
}
shadowJar {
mergeServiceFiles()
}
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1')
mainClassName = "sillynaut.Application"
compileJava.options.compilerArgs += '-parameters'
compileTestJava.options.compilerArgs += '-parameters'
jib.to.image = 'gcr.io/sillynaut/jib-image'
I managed to workaround the issue by changing the dependency scope of io.micronaut:inject from implementation to compile. But I was wondering why the CLI generates dependencies using scope of Gradles java-library plugin but only applies the Gradle java plugin.
Since IntelliJ is usually very good in setting the dependency scopes I was wondering if this is a bug. Can anyone confirm or explain this?
Make sure that you enable the annotation processors.
in Intelij:
File > Setting > Build, Execution, Deployment > Compiler > annotation processors then enable it

How to invoke selenium test into a Jenkins

I am new to Jenkins.
I have sample selenium code like below in Java project:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SampTest
{
public static void main(String[] args)
{
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println(driver.getTitle());
driver.quit();
}
}
This works perfect.
I configured like below in Jenkins:
Create a new project with name.
In Advanced options, added Workspace as "D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src"
In build section, i used Execute Windows batch command like "javac SampTest.java | java SampTest"
(Basically i dont know what to use here. Can someone help me here).
When i build the project now i see an error message saying below:
Started by user anonymous
Building in workspace D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src
[src] $ cmd /c call C:\Users\user\AppData\Local\Temp\hudson578216989100659838.bat
D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src>javac SampTest.java | java SampTest
java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" SampTest.java:1: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
SampTest.java:2: error: package org.openqa.selenium.firefox does not exist
import org.openqa.selenium.firefox.FirefoxDriver;
^
SampTest.java:8: error: cannot find symbol
WebDriver driver=new FirefoxDriver();
^
symbol: class WebDriver
location: class SampTest
SampTest.java:8: error: cannot find symbol
WebDriver driver=new FirefoxDriver();
^
symbol: class FirefoxDriver
location: class SampTest
4 errors
D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src>exit 1
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE