serve icon indicating copy to clipboard operation
serve copied to clipboard

java.lang.NoSuchMethodError when starting Torch Serve

Open VarunNatraaj opened this issue 6 years ago • 13 comments

I keep getting this path not found error.

This is from starting the torchserve inside a project:

torchserve --start --model-store model_store --models densenet161=densenet161.mar

% java.lang.NoSuchMethodError: java.nio.file.Files.readString(Ljava/nio/file/Path;)Ljava/lang/String;
	at org.pytorch.serve.util.ConfigManager.readFile(ConfigManager.java:196)
	at org.pytorch.serve.util.ConfigManager.<init>(ConfigManager.java:108)
	at org.pytorch.serve.util.ConfigManager.init(ConfigManager.java:246)
	at org.pytorch.serve.ModelServer.main(ModelServer.java:70)

This is from after pulling and building torchserve from git, and running the torchserve_sanity.sh script:

> Task :modelarchive:test
objc[37989]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java (0x10b9184c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10b9924e0). One of the two will be used. Which one is undefined.

ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.CoverageTest > test PASSED

ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.ModelArchiveTest > test PASSED

ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.ModelArchiveTest > testInvalidURL PASSED

ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.ModelArchiveTest > testMalformURL PASSED

> Task :server:compileJava FAILED
/Users/hariharan/Petprojects/torchserve/serve/frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java:196: error: cannot find symbol
        return Files.readString(Paths.get(path));
                    ^
  symbol:   method readString(Path)
  location: class Files
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':server:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
18 actionable tasks: 18 executed
Frontend build suite execution failed!!! Check logs for more details

Any ideas or help here please? Also, here's my environment info:

Mac OSX Catalina 10.15.4 (19E287)

% python --version
Python 3.7.4

torch                    1.5.1
torch-model-archiver     0.1.1
torchserve               0.1.1
torchtext                0.6.0
torchvision              0.6.1

% java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

VarunNatraaj avatar Jun 22 '20 18:06 VarunNatraaj

You need java 11 for this. Please look at the quick start guide here

codinnvrends avatar Jun 23 '20 03:06 codinnvrends

Ah sorry. My bad then. I thought Java 8 was the minimum requirement according to this. Let me try with Java 11.

VarunNatraaj avatar Jun 23 '20 06:06 VarunNatraaj

Works now. Sorry for the trouble!

VarunNatraaj avatar Jun 23 '20 07:06 VarunNatraaj

I am getting the same error

(torch_serve1) kanchan.sarkar:~$ java.lang.NoSuchMethodError: java.nio.file.Files.readString(Ljava/nio/file/Path;)Ljava/lang/String; at org.pytorch.serve.util.ConfigManager.readFile(ConfigManager.java:202) at org.pytorch.serve.util.ConfigManager.(ConfigManager.java:114) at org.pytorch.serve.util.ConfigManager.init(ConfigManager.java:252) at org.pytorch.serve.ModelServer.main(ModelServer.java:70)

when my java version is

openjdk version "11.0.5" 2019-10-15 OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-2ubuntu116.04) OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-2ubuntu116.04, mixed mode, sharing)

please let me know if I am doing anything wrong?

KanchanIIT avatar Aug 27 '20 07:08 KanchanIIT

@KanchanIIT: I suspect there are multiple Java versions installed on your machine. Could you please share the output of the following command:

dpkg --list | grep -i jdk

Also share the details about your environment and steps you executed which caused this error.

harshbafna avatar Aug 27 '20 08:08 harshbafna

@SysuCharon: Could you please log a fresh ticket with your environment details per the bug report template?

harshbafna avatar Oct 20 '20 09:10 harshbafna

Facing the same issue on Ubuntu16.04 with PyTorch1.7.1. Related information is listed as follows:

java -version

openjdk version "11.0.5" 2019-10-15 OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-2ubuntu116.04) OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-2ubuntu116.04, mixed mode, sharing)

dpkg --list | grep -i jdk

ii openjdk-11-jdk:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Development Kit (JDK) ii openjdk-11-jdk-headless:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Development Kit (JDK) (headless) ii openjdk-11-jre:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Java runtime, using Hotspot JIT ii openjdk-11-jre-headless:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Java runtime, using Hotspot JIT (headless)

lucasxlu avatar Dec 28 '20 06:12 lucasxlu

@lucasxlu: Could you please create a fresh ticket with details per the bug report template? Please also share the details of the steps followed

harshbafna avatar Dec 28 '20 06:12 harshbafna

@SysuCharon: Could you please log a fresh ticket with your environment details per the bug report template? @harshbafna thank u I have solved this problem Install JDK first and then torch serve

SysuCharon avatar Dec 29 '20 07:12 SysuCharon

sudo apt-get install openjdk-11-jdk

This worked for me

seems like it should have installed JAVA like this first if using cuda. Didnt work for me

python ./ts_scripts/install_dependencies.py --cuda=cu102

joemal1234 avatar Sep 01 '22 16:09 joemal1234

You need java 11 for this. Please look at the quick start guide here

I recommend adding in torchserve one line of code checking for appropriate java version, and print a good error message.

ndvbd avatar Feb 07 '23 14:02 ndvbd

You need java 11 for this. Please look at the quick start guide here

@dhaniram-kshirsagar this page doesn't mention the term 'java'

ndvbd avatar Feb 07 '23 14:02 ndvbd

This error usually occurs when Java 17 is not installed or used. Java 17 is required by Torchserve and older java versions are not supported. https://pytorch.org/serve/Troubleshooting.html#java-lang-nosuchmethoderror-when-starting-torchserve-473

vvasil-mindwave avatar Mar 12 '24 15:03 vvasil-mindwave