Error: Could not find or load main class com.javabnp.mainRunner

(Didier) #1

Dear all,

I created a gradle java project with intellij. In this project i first created my Main java class who then creates a scala object from an imported self created package.
I followed the suggestion from

And with this i can build , but the runScala and runJava task are not working and the resulting jar file with the build task gives me an error like:
java -jar JavaTOscala-1.0-SNAPSHOT.jar
Scala launched10
Starting scalaRunner Singleton Object
Exception in thread “main” java.lang.NoClassDefFoundError: scala/collection/Seq
at com.scalabnp.scalaRunner.StartRead(scalaRunner.scala)
at com.javabnp.MainRunner.main(
Caused by: java.lang.ClassNotFoundException: scala.collection.Seq
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
… 2 more

Here is the very simple javacode:
package com.javabnp;

import com.scalabnp.scalaRunner;

class MainRunner {

        public static void main (String[] args)
                scalaRunner SC = new scalaRunner();
                System.out.println("Scala launched" + SC.printme(5));
                System.out.println("Starting scalaRunner Singleton Object");

and here is the scalacode:

package com.scalabnp
import scala.sys.process._

class scalaRunner {

def printme(x: Int) : Int={
  return x * 2;


object scalaRunner {

  def someProcessing(line: String): Unit = {
    print("[just read this line] ")

  // the file to read
  val file = "/var/log/wifi.log"

  // the process to start
  val tail = Seq("tail", "-f", file)
  def StartRead(): Unit = {

And here is the build.gradle file:
group 'Scalalearn’
version ‘1.0-SNAPSHOT’

apply plugin: 'java'
apply plugin: 'scala'

sourceCompatibility = 1.8

repositories {
def mainClassName = "com.javabnp.MainRunner"

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'org.scala-lang:scala-library:2.11.8'
    compile group: 'org.apache.kafka', name: 'kafka_2.10', version: ''
    compile group: 'org.apache.flink', name: 'flink-scala_2.11', version: '1.4.0'
    testCompile 'org.scalatest:scalatest_2.11:3.0.0'
    testCompile 'junit:junit:4.12'
    testRuntime 'org.scala-lang.modules:scala-xml_2.11:1.0.6'

jar {
    manifest {
                'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
                'Main-Class': 'com.javabnp.MainRunner'
sourceSets {
    main.scala.srcDir "src/main/java" = []
    test.scala.srcDir "src/test/java" = []

task runJava(type: JavaExec, dependsOn: classes) {
    main= 'com.javabnp.mainRunner'
    classpath sourceSets.main.runtimeClasspath
    classpath configurations.runtime
task runScala(type: JavaExec, dependsOn: classes) {
    main= 'com.scalabnp.scalaRunner'
    classpath sourceSets.main.runtimeClasspath
    classpath configurations.runtime

Thanks for your help and advice,

(Didier) #2

Forgot to add the runJava and runScala both gives the same error in intellij:
Run tasks 597ms
:compileJava 2ms
:compileScala 76ms
Resolve dependencies :compileClasspath 11ms
Resolve dependencies :detachedConfiguration1 6ms
Resolve dependencies :zinc 11ms
:processResources 11ms
:classes 1ms
**:runScala 490ms **
Resolve dependencies :runtime 11ms