Resolve CreateProcess error = 206 when running Java in a Windows environment

While developing with Java, the following error started to occur and I was quite addicted to it, so make a note.

Exception occurred executing command line. 
Cannot run program "C:\Program Files\Java\jre1.8.0_144\bin\javaw.exe" (in directory "C:\Users\ore\myproject"): CreateProcess error=206, The filename or extension is too long

Cause

When I first saw it, I didn't understand it at all, but the specified string of classpath specified when executing the java command (java -cp "c: \ myproject \ main; c: \ Users \ .gradle \ .. .. It seems that the cause is that "Mita-natsu" is too long and exceeds the maximum number of characters of the argument of createProcess in Windows, 32768.

Coping

Reduce library

This is the best if you can choose this. This time it was impossible because all the libraries were necessary.

Move the project directory down the hierarchy

For example, if it is now in c: \ Users / ore / nanika / nantoka / are / sore / koko, move to c: \ Users / ore /. I thought this would be the next easiest thing to do, but it didn't work. The reason is in the next item.

Change Gradle's home directory

If you look closely at the classpath specified in the java command when the error occurs, it is very often something like c: \ Users \ ore \ .gradle \ nantoka_library \ nantoka.jar. So I moved the default download destination of gradle from c: \ Users \ ore \ .gradle to c: \ .gradle.

In Windows, create GRADLE_USER_HOME in "System"-> "Advanced system settings"-> "Environment variables"-> User environment variables and specify the value in the procedure of C: \ .gradle.

Now I restarted the IDE and rebuilt it and it worked. It's not a good idea, but if you're addicted to it, it might be worth a try.

Isn't there a proper countermeasure in the first place?

The problem is that the java command has too long arguments, so you can stop doing this. If you can use Java 9 module, you don't need to specify such a large number of long classpaths. However, it will take some time before Java 9 becomes widespread and the library supports it.

Recommended Posts

Resolve CreateProcess error = 206 when running Java in a Windows environment
Show detailed error in Logger when running Java on server
When seeking multiple in a Java array
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Error in bundle install when running rails new
When there are environment variables in Java tests
A note when you want Tuple in Java
A bat file that uses Java in windows
When using a list in Java, java.awt.List comes out and an error occurs
How to create a Java environment in just 3 seconds
Points stuck when running vite + Nginx in Docker environment
Verification value error that occurred in a clustering environment
What I learned when building a server in Java
Deploying a Java environment with Windows Subsystem for Linux (WSL)
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Avoid Yubaba's error in Java
Use Java Web Start in an OpenJDK environment on Windows
Change java encoding in windows
Find a subset in Java
JavaFX environment construction in Java 13
Error when playing with java
Ruby ① Build a Windows environment
Zip compression with Java in Windows environment without garbled characters
Collecting client information when an error occurs in a web application
Symbol not found error when new class in another Java file
How to automatically operate a screen created in Java on Windows
Remedy for "A server is already running." Error when running rails s
I got a Permission Denied error when I put Laravel in Docker
Avoid character code error in java when using VScode extension RUN-CODE
How to solve the unknown error when using slf4j in Java
I created a PDF in Java.
Java Spring environment in vs Code
<java> When "EXCEPTION_ACCESS_VIOLATION" appears in awt
Encoding when getting in Windows + Ruby
Create a database in a production environment
Try running Selenuim 3.141.59 in eclipse (java)
Java environment variable settings (Windows, AdoptOpenJDK11)
A simple sample callback in Java
Try running AWS X-Ray in Java
Get stuck in a Java primer
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
What I checked when I installed Docker Hub in a Windows 10 home environment but it did not start
Bad habits pointed out in code reviews when Java was a beginner
Avoid Java encoding errors that occur when running FitGen.exe on Japanese Windows
How to pass a proxy when throwing REST over SSL in Java
How to get the absolute path of a directory running in Java
About returning a reference in a Java Getter
Java container performance degradation in Menicoa environment
What is a class in Java language (3 /?)
Building a Lambda development environment in Eclipse
Call the Windows Notification API in Java
[Creating] A memorandum about coding in Java
Java creates a table in a Word document
Java creates a pie chart in Excel
What is a class in Java language (1 /?)
Let's create a Java development environment (updating)
Play Framework 2.6 (Java) environment construction in Eclipse
Error in implementation when implementing Spring validation
What is a class in Java language (2 /?)
Try running a Kubernetes Job from Java
Create a TODO app in Java 7 Create Header