Why doesn't this gradle build script compile a java class?

I am trying to use Cascading in my Hadoop project. I am trying to implement the first example given in the book Enterprise Data Workflows with Cascading . I wrote a java class that contains Cascading related code, and I have another build.graddle file that should compile this Java class and create a jar file from it.

My folder structure is as follows:

  • main_folder

    • impatient

      • Main.java
      • build.gradle

My build.gradle file is as follows:

 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 the gradle clean jar command from the command line, I get a successful build message. I tried to run this jar file using

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

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

So, I checked the contents of the jar file and found that this jar does not contain the impatient/Main.class .

Please note that I do not know anything about gradle .

Ask someone to tell me if something is wrong with the gradle script or I am wrong.

Thanks!!!

+6
source share
1 answer

Move the source file to

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

but leave the build.gradle file where it is.

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

+9
source

Source: https://habr.com/ru/post/953631/


All Articles