Why this gradle build script is not compiling java class?
Asked Answered
A

1

7

I am trying to use Cascading in my Hadoop project. I am trying to implement first example given in Enterprise Data Workflows with Cascading book. I have written java class which contains Cascading related code and I have another build.graddle file which is supposed to compile that java class and build jar file out of it.

My folder structure is as follows :

  • main_folder

    • impatient

      • Main.java
      • build.gradle

My build.gradle file looks as below :

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'

archivesBaseName = 'impatient'
repositories {
    mavenLocal()
    mavenCentral()
    mavenRepo name: 'conjars', url: 'http://conjars.org/repo/'
}
ext.cascadingVersion = '2.1.0'
dependencies {
    compile( group: 'cascading', name: 'cascading-core', version: cascadingVersion )
    compile( group: 'cascading', name: 'cascading-hadoop', version: cascadingVersion )
}
jar {
    description = "Assembles a Hadoop ready jar file"
    doFirst {
        into( 'lib' ) {
            from configurations.compile
        }
    }
    manifest {
        attributes( "Main-Class": "impatient/Main" )
    }
}

When I run gradle clean jar command from command prompt, I get build successful message. I tried to run this jar file using

hadoop jar impatient.jar <input file path> <output file path>

command but then it gives me Exception in thread "main" java.lang.ClassNotFoundException: impatient.Main exception.

So I checked contentes of jar file and found that that jar does not contain impatient/Main.class file.

Please note that I do not know anything about gradle.

Request someone to please tell me if there is anything wrong with gradle script or I am making some mistake.

Thanks !!!

Agretha answered 11/9, 2013 at 13:36 Comment(1)
I'm not sure here but I think "Main-Class": "impatient.Main" is the way to go, or even "mainClassName=impatient.Main". Check gradle.org/docs/current/userguide/application_plugin.htmlOverpower
P
10

Move your source file to

main_folder/impatient/src/main/java/Main.java

but leave build.gradle file where it is.

By default, Gradle uses src/main/java and src/test/java to look for production and test java sources (relative to root folder, which is impatient in your case)

Parting answered 13/9, 2013 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.