DEV Community

Cameron Paige
Cameron Paige

Posted on

Fixing "not found: java" Mock API endpoint error

TL;DR: Download the Java SDK, then manually add the path to your environment variables.


"My middle name is Edge Case," I joked, my hand the only one raised in a room of about 100 people. At that moment, I was the only person still unable to get amplify mock api to work on the command line.

The problem? No java:

Screenshot of Git Bash CLI with red message "Failed to start API Mock endpoint Error: not found: java"
Easy fix. I found what I thought would be the right npm package and blithely hit Enter.

I got back a wall of error messages, mostly having to do with gyp missing Python:

Screenshot of Git Bash CLI with multiple "gyp ERR! find Python" error messages and instructions for installing Python

Thankfully, somebody nearby was having a similar issue and had just solved it by downloading the Java SDK directly from Oracle.

I grabbed the Windows version, installed it, and ran amplify mock api again. Again, it told me I had no java.

I went into Programs and checked. There it was, happily ensconced between Internet Explorer (huh?) and Killer Networking (uhm... huh?).

Maybe it was telling me I needed more coffee? I tried that. No luck.

Photo of two coffee dispensers both labeled "Breakfast Blend"

But then something clicked. I remembered similar issue I'd ran into during boot camp (the only Windows 10 user in my class). The solution then was to manually enter the path into Environment Variables.

To try that, I went to the Control Panel\System and Security\System and clicked on Advanced system settings.

Screenshot of Windows Control Panel with the link to Advanced system settings highlighted in blue

In the System Properties/Advanced panel that opened, I clicked on Environment Variables.

Screenshot of the System Properties/Advanced panel with the Environment Variables button highlighted in blue

That took me to the panel with User and System variables, both including the option to add a new Path.

Screenshot of the System Variables panel with Path highlighted in gray for User variables and blue for System

I first selected the User variables Path and clicked on Edit. That took me to the Edit environment variable panel with an option to add a new Path.

Screenshot of the Edit environment variable panel with New button and an empty row under existing paths highlighted in blue

To make sure I entered the path correctly, I used the File Explorer to navigate into the bin folder for Java, then right clicked on the address to copy it.

Screenshot of a File Explorer window opened to the bin folder inside the Java folder, with the option to copy the address highlighted

I copied and pasted it into both User and System Path variables, and clicked OK.

Screenshot of the Edit environment variable panel with the copied address pasted into the row under existing paths and the OK button highlighted in blue

After that, I kept clicking OK until I was out of the Control Panel. Then, for the changes to register with the CLI, I had to close and reopen it again. Finally, I ran amplify mock api one more time...

It worked!

And so, at long last, I could carry on with the workshop, building real-time offline-ready applications with React, GraphQL & AWS AppSync.

Top comments (1)

Collapse
 
312akim profile image
Alexander Kim

This helped me. Thank you Cameron! Watching the video upload, youtube.com/watch?v=HZUlQ7Z2xHQ to gain mastery over AWS & Amplify.