2

The project runs perfectly using Netbean's "build and run". However, due to the need to create a Fat Jar I had to add a gradle task CustomFatJar in build.gradle which looks like this:

    task customFatJar(type: Jar) {
    manifest {
        attributes 'Main-Class': 'com.Reject.Main'
    }
    baseName = 'all-in-one-jar'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

Thus, running the gradle like this using command prompt:

gradle customFatJar

and then get this result :

 error: cannot find symbol
 try (InputStream is = Files.newInputStream(Path.of(""), StandardOpenOption.READ)) {
                                                       ^
 symbol:   method of(java.lang.String)
 location: interface java.nio.file.Path

I believe I have imported Java nio file path in the main class:

 import java.nio.file.Path;

I could not find any clue how to fix this as the code runs completely fine in the IDE.

TylerP
  • 9,600
  • 4
  • 39
  • 43
  • can you post the block of code that causing error? – dadan Sep 27 '21 at 05:32
  • You are probably building with a JDK older than 11. – Bjørn Vester Sep 27 '21 at 07:46
  • Can you please share the output of `java -version` when running from a terminal you use to build your project? – akortex Sep 27 '21 at 08:45
  • @dadan try (InputStream is = Files.newInputStream(Path.of(path+dt_formatter.format(new Date())+".jrn"), StandardOpenOption.READ)) { } catch {...} finally{....} its more of like that. I would like to edit my question instead of posting it here but I couldn't find the button :( – Andhika Gannesha Gemilang Sep 27 '21 at 11:16
  • @BjørnVester java version "11.0.12" 2021-07-20 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode) – Andhika Gannesha Gemilang Sep 27 '21 at 11:19
  • @akortex thats the java version – Andhika Gannesha Gemilang Sep 27 '21 at 11:20
  • And is that the same version as when you run `gradle --version`? The reason we ask is that the `Path.of` method was first introduced in Java 11, so if you compile with a prior version you will get an error as you've shown. – Bjørn Vester Sep 27 '21 at 12:41
  • @BjørnVester totally missed that one, yes the gradle --version says java 1.8 and i follow this instruction : [link](https://stackoverflow.com/questions/18487406/how-do-i-tell-gradle-to-use-specific-jdk-version) `gradle build -Dorg.gradle.java.home=/JDK_PATH` Many Thanks – Andhika Gannesha Gemilang Sep 29 '21 at 14:22
  • You can also use the `JAVA_HOME` environment variable to set the path to the java distribution if that is easier for you. – Bjørn Vester Sep 29 '21 at 16:40

0 Answers0