150

I have this error in eclipse helios:

Exception occurred executing command line. Cannot run program "C:\Program Files (x86)\Java\jre6\bin\javaw.exe" (in directory "C:\Users\motiver\helios_workspace\TimeTracker"): CreateProcess error=206, The filename or extension is too long

I researched a bit but most of the issues were related to DataNucleus when working on Google App Engine. But I am not using anything remotely related to Google App Engine. I am doing a small project with Servlet 3.0 on JBOSS 6. I am using Hibernate 4.1.2 for ORM and RESTEasy to expose a web service. I created a util file that has a main() method that basically drops and re-creates the schema. I run the main() methos when I need a clean database for testing purposes. It worked fine on Tomcat 7 but it stopped working when I moved to JBoss 6.

Any hint or solution would be greatly appreciated.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
motiver
  • 2,242
  • 4
  • 19
  • 20
  • possible duplicate of [CreateProcess error=206, The filename or extension is too long](http://stackoverflow.com/questions/8850920/createprocess-error-206-the-filename-or-extension-is-too-long) – Ernest Friedman-Hill May 09 '12 at 15:55
  • Might be useful: https://bugs.eclipse.org/bugs/show_bug.cgi?id=327193 – Jeremy May 09 '12 at 16:01
  • I want to understand whether `C:\Program Files (x86)\Java\jre6\bin\javaw.exe` is long or the other one `C:\Users\motiver\helios_workspace\TimeTracker`. I'm also having the same problem. – Siva R Feb 27 '17 at 05:22
  • 2
    Posterity: I had a similar situation but, with a simple enterprise application deployed on WLS and client from on Eclipse. What I noticed was the classpath was enormous as Eclipse, by default, included entire WLS library(all jars). I removed it and added, just, weblogic.jar(only required). Afterwards, it worked fine. So, by my observation, just remove unnecessary jars. – lupchiazoem Jan 11 '19 at 12:18

33 Answers33

62

There is no simple (as in a couple of clicks or a simple command) solution to this issue.

Quoting from some answers in this bug report in Eclipse.org, these are the work-arounds. Pick the one that's the least painful to you:

  • Reduce the classpath
  • Use directories instead of jar files
  • Use a packed jar files which contains all other jars, use the classpath variable inside the manifest file to point to the other jars
  • Use a special class loader which reads the classpath from a config file
  • Try to use one of the attached patches in the bug report document
  • Use an own wrapper e.g. ant

Update: After July 2014, there is a better way (thanks to @Brad-Mace's answer below:

If you have created your own build file instead of using Project -> Generate Javadocs, then you can add useexternalfile="yes" to the Javadoc task, which is designed specifically to solve this problem.

espinchi
  • 9,144
  • 6
  • 58
  • 65
  • Thanks for the great suggestions. I exported the project as a runnable jar from within eclipse and did a command line "java -jar MyJar.jar" and it works perfectly fine. I guess this is somewhat similar to your 3rd bullet point. – motiver May 15 '12 at 22:17
  • 22
    How would IntelliJ *not* have this problem if it's entirely because of the length of the classpath used when launching the JVM? – nitind Jun 28 '12 at 04:54
  • 1
    This might be eclipse problem only, I am able to run the app using maven. – surajz Oct 02 '12 at 20:05
  • 4
    @nitind "In IntelliJ IDEA they substitute the main class with a generated one. It contains the hardcoded classpath and the code to launch the original main class." Taken from https://bugs.eclipse.org/bugs/show_bug.cgi?id=327193#c8 – Chobicus Apr 25 '13 at 12:49
  • 3
    In 2014, this answer is wrong and the one by @Brad Mace is correct. – Bananeweizen Jun 30 '14 at 05:19
  • 6
    "Reduce the classpath" is a nice hint, but let me elaborate a little bit on this: In my case, I tried to build a maven project, and the `-classpath` argument was generated to contain all the dependencies. So, something like this came out: `C:\Users\myself\.m2\repository\…;C:\Users\myself\.m2\repository\…[…tons more]`. Moving my local maven repo cache to `D:\m2` did the trick: Classpath shrank down to `D:\m2\…;D:\m2\…` - bingo! Remember to set the `localRepository` path in your maven config. – ThomasR Aug 27 '16 at 08:49
  • @ThomasR, this is an effective solution if the user just got this error after adding a few dependencies. of course it does't help if dependencies are **too** many. – Lei Yang Dec 11 '18 at 13:56
  • I had the same problem, the culprit was the extra jar files ( read 300+ ) which are not at all referenced by the project. So removed those and was able to proceed further. – Pavan Dittakavi Apr 19 '19 at 08:30
25

**enter image description here**

In intellij there is an option to 'shorten command line', select 'JAR manifest' or '@argFiles' would solve the problem, basically it will put your lengthy class path into a jar file or a temp file

actan
  • 635
  • 2
  • 9
  • 17
  • 2
    Worked!. Took me for a while to figure out where it is. Select Application > Edit Configurations – Rico Nguyen Jan 19 '21 at 10:01
  • Alternative methods to shorten command line: https://stackoverflow.com/questions/47926382/how-to-configure-shorten-command-line-method-for-whole-project-in-intellij – Fissure Apr 28 '21 at 13:56
23

If you create your own build file rather than using Project -> Generate Javadocs you can add useexternalfile="yes" to the javadoc task, which is designed specifically to solve this problem.

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
22

I faced this problem today and I was able to solve it using this Gradle plugin

It's github url is this

IF you, like me, have no idea what Gradle is but need to run a backend to do your front end work, what you need to do is find the build.gradle file that is being called to start your BE server and add this to the top:

plugins {
  id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
}
Alejandro B.
  • 4,807
  • 2
  • 33
  • 61
  • 6
    Now I get "Main class name has not been configured and it could not be resolved", despite having set `attributes["Main-Class"]` – Anton3 Sep 12 '19 at 08:39
  • 2
    I tried using plugin but no effect . Issue is still coming. Please suggest – amarnathpatel Oct 25 '19 at 07:57
  • For me a similar plugin worked by adding `plugins { id "com.github.ManifestClasspath" version "0.1.0-RELEASE" }` and `mainClassName = "com.sample.YourMainClass"` – TomasZ. Jan 17 '22 at 13:15
18

I was running into this issue trying to execute a JPQL query in the Hibernate / JPA console of IntelliJ 2020.2

Adding this to my .idea/workspace.xml fixed it

<component name="PropertiesComponent">
 
...
     <property name="dynamic.classpath" value="true"/>
 
...
 
</component>

Origin of the solution: https://youtrack.jetbrains.com/issue/IDEA-166929?_ga=2.167622078.1290412178.1604511702-23036228.1574844686

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
8

Answering my own question here so that the solution doesn't get buried in comments. I exported the project as a runnable jar from within eclipse and did a command line "java -jar MyJar.jar" and it works perfectly fine

motiver
  • 2,242
  • 4
  • 19
  • 20
7

This is not specifically for eclipse, but the way I got around this was by creating a symbolic link to my maven repository and pointing it to something like "C:\R". Then I added the following to my settings.xml file:

<localRepository>C:\R</localRepository>

The maven repository path was contributing to the length problems in my windows machine.

Shygar
  • 1,213
  • 10
  • 10
6

Try updating your Eclipse version, the issue was closed recently (2013-03-12). Check the bug report https://bugs.eclipse.org/bugs/show_bug.cgi?id=327193

Rodrigo
  • 483
  • 8
  • 14
6

Question is old, but still valid. I come across this situation often whenever a new member joins my team or a new code segment is added to existing code. Simple workaround we follow is to "Reduce the classpath" by moving up the directories.

As question mentioned, this is not specific to eclipse. I came across this issue in IntelliJ Idea 14 and 2018 as well.

After a long research, I found the solution is to set the

fork = false

in javc of ant build file.

<javac destdir="${build.dir}" fork="false" debug="on">
    <classpath .../>
    <src ... />
    <patternset ... />
</javac>

This is how my ant build javac looks now. To learn about more on fork, please refer ant documentation.

Don D
  • 726
  • 1
  • 9
  • 19
3

In bug report Bug 327193 it is considered fixed, but it happen to me recently with Eclipse Kepler 4.3.2.

Please download patch for Eclipse Juno or newer:

https://bugs.eclipse.org/bugs/attachment.cgi?id=216593

  1. After download back up existing eclipse/plugins/org.eclipse.jdt.launching_3.*.jar
  2. Copy and paste classes in the patch to org.eclipse.jdt.launching JAR (replace existing files).
  3. Restart Eclipse.
Maciej Dzikowicki
  • 859
  • 1
  • 10
  • 10
  • This worked for me. Note that applying this removed my JDK Java installations from Installed JREs. I had to re-add them again. Only 1 JRE installation persisted. – Joetjah Jun 27 '14 at 11:24
  • Funny thing, you look for answers on SO on your issue and one of the answers is from a person you used to study/work with :) – Michał Szkudlarek Jul 09 '20 at 15:06
3

Add below to your gradle file:

plugins {
`id "com.github.ManifestClasspath" version "0.1.0-RELEASE"       
}

See https://plugins.gradle.org/plugin/com.github.ManifestClasspath

MMG
  • 3,226
  • 5
  • 16
  • 43
Scar Coder
  • 387
  • 3
  • 7
  • This is not working in my case. I had studio's JRE in shortest path possible in directory still the error came. only resolution so far deleting java.exe process. – Mohit Dixit Jun 07 '21 at 08:18
3

How many people sad above, there are a lot of plugins to gradle execute a by pass in this problem like:

plugins {
  id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
}

or

plugins {
  id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}

But the better solution that I found was kill the JVM process and everything is done.

Ivan Rodrigues
  • 441
  • 4
  • 20
  • Adding either of the two results in > Main class name has not been configured and it could not be resolved Any idea how to go around it? I have no idea what Gradle is, unfortunately – Varad Pimpalkhute Sep 28 '21 at 12:20
2

Try adding this in build.gradle (gradle version 4.10.x) file and check it out com.xxx.MainClass this is the class where your main method resides:

plugins {
  id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
}
apply plugin: 'application'
application {
    mainClassName = "com.xxx.MainClass"
}

The above change must resolve the issue, there is another way using script run.sh below could fix this issue, but it will be more of command-line fix, not in IntelliJ to launch gradle bootRun.

ravibeli
  • 484
  • 9
  • 30
  • A dumb question, but what needs to replaced in xxx? – Varad Pimpalkhute Sep 28 '21 at 12:26
  • 1
    If you have Application.java having main method and this class is in package example: `com.example.demo` then in build.gradle you have to mention `mainClassName = "com.example.demo.Application"` – ravibeli Oct 01 '21 at 10:14
2

I am using legacy version of gradle plugins and this plugin solved the issue for me.

Usage (check source for more details):

Build script snippet for plugins DSL for Gradle 2.1 and later

plugins {
  id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}

Build script snippet for use in older Gradle versions or where dynamic configuration is required

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
  }
}

apply plugin: "com.github.ManifestClasspath"
Ilkin
  • 386
  • 3
  • 17
1

I have got same error, while invoking Maven.

The root cause for my problem was the classpath was very huge. Updating the classpath fixed the problem.

There are multiple ways to update the large classpath as mentioned in this: How to set a long Java classpath in Windows?

  1. Use wildcards
  2. Argument File
  3. Pathing jar

Since I am using Intellij, they provide the option to use Argument File that i used.

Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121
1

Try this:

java -jar -Dserver.port=8080 build/libs/APP_NAME_HERE.jar

1

To solve it:

If you are using Eclipse:

Move .m2 repository to

c:\ Go to Eclipse > Windows/Preferences/Maven/User Settings -> Create your own setting.xml with its content:

<settings>
  <localRepository>c:/.m2/repository</localRepository>
</settings>

If you are using IntelliJ: Go to IntelliJ > clicking the right mouse button on "pom.xml" > maven > create "settings.xml"

with its content:

<settings>
      xmlns="yourcontent"
      xmlns:xsi="yourcontent"
      xsi:schemaLocation="yourcontent.xsd">
  <localRepository>c:/.m2/repository</localRepository>
</settings>
R. Pereira
  • 205
  • 1
  • 3
  • 10
1

In my case the error was showing because system java version was different from intellijj/eclipse java version. System and user had diff java versions. If you compile your code using one version and tried to run using a different version, it will error out. User java version is 1.8

#The system java version is 1.7.131
$ java -version
java version "1.7.0_131"

Long story short, make sure your code is compiled and ran by the same java version.

z atef
  • 7,138
  • 3
  • 55
  • 50
1

In a Windows machine, there is a limitation of the jar file name/path length in the command-line, due to which you see the below error message, I tried searching a lot, even I tried applying the above solution, some reason, it didn't work, I found the working snippet for Gradle (gradle-4.10.2-all.zip)

Error:

CreateProcess error=206, The filename or extension is too long

Use this below gradle.build code snippet to fix the above problem in IntelliJ or STS, or eclipse anything.

Gradle Code Fix:

apply plugin: 'application'

task pathingJar(type: Jar) {
    dependsOn configurations.runtime
    appendix = 'pathing'

    doFirst {
        manifest {
            attributes "Class-Path": configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
        }
    }
}

task copyToLib(type: Copy) {
    into "$buildDir/libs"
    from configurations.runtime
}

bootRun {
    systemProperties = System.properties
    //This below line is for if you have different profiles prod, dev etc...
    //systemProperty 'spring.profiles.active', 'dev'
    jvmArgs('-Djava.util.logging.config.file=none')
    mainClassName = "com.xxxx.Main"
    dependsOn pathingJar
    dependsOn copyToLib
    doFirst {
        classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", pathingJar.archivePath)
    }
}
ravibeli
  • 484
  • 9
  • 30
1

For me it was wrong JDK path. Please make sure you have right path to the JDK file

File -> Project Structure

enter image description here

Muhammad Hamza Shahid
  • 956
  • 1
  • 15
  • 23
1

If you are using VSCode:

  1. create launch.json file insde .vscode/

  2. add

    {"configurations": [{ "type": "java","shortenCommandLine ": "auto",}]}
    

If you are using intellij :

  1. open .idea/workspace.xml

  2. inside <component name="PropertiesComponent"> add <property name="dynamic.classpath" value="true"/>

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

it happens due to DataNucleus sometimes overwrite the Arguments with many paths.

You have to overwrite them with this:

-enhancerName ASM -api JDO -pu MediaToGo

Hope help you!

Rodrigohsb
  • 11
  • 3
0

I got the same error. Tried solutions like cleaning, rebuild, invalidateCache, retart etc but nothing works.

I just have created a new folder with short name and copied all the files(app folder, gradle files etc) in new folder. Opened application in android studio and its working fine.

Tara
  • 2,598
  • 1
  • 21
  • 30
0

To fix this below error, I did enough research, not got any great solution, I prepared this script and it is working fine, thought to share to the public and make use of it and save there time.

CreateProcess error=206, The filename or extension is too long

If you are using the Gradle build tool, and the executable file is placed in build/libs directory of your application. run.sh -> create this file in the root directory of your project, and copy below script in it, then go to git bash and type run.sh then enter. Hope this helps!

#!/bin/bash
dir_name=`pwd`
if [ $# == 1 ] && [ $1 == "debug" ]
then
    port=$RANDOM
    quit=0
    echo "Finding free port for debugging"
    while [ "$quit" -ne 1 ]; do
        netstat -anp | grep $port >> /dev/null
        if [ $? -gt 0 ]; then
            quit=1
        else
            port=`expr $port + 1`
        fi
    done
    echo "Starting in Debug Mode on "$port
    gradle clean bootjar
    jar_name="build/libs/"`ls -l ./build/libs/|grep jar|grep -v grep|awk '{print $NF}'`
    #java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$port $jar_name 
elif [ $# == 1 ] && [ $1 == 'help' ]
then
    echo "please use this commands"
    echo "------------------------"
    echo "Start in Debug Mode: sh run.sh debug"
        echo "Start in Run Mode: sh run.sh" 
    echo "------------------------"
else
    gradle clean bootjar
    word_count=`ls -l ./build/libs/|grep jar|grep -v grep|wc -w`
    jar_name=`ls -l ./build/libs/|grep jar|grep -v grep|awk '{print $NF}'`  
    jar_path=build/libs/$jar_name
    echo $jar_name
    #java -jar $jar_path
fi

Hope this helps!!

TomasZ.
  • 449
  • 1
  • 5
  • 10
ravibeli
  • 484
  • 9
  • 30
0

If you are using Android Studio try Invalidate Caches/ Restart.. option present in File menu

SagaRock101
  • 129
  • 1
  • 7
0

I used com.virgo47.ClasspathJar plugin to fix this issue https://plugins.gradle.org/plugin/com.virgo47.ClasspathJar

m4n0
  • 29,823
  • 27
  • 76
  • 89
0

You can use below commands:

mklink /J c:\repo C:\<long path to your maven repository> 


mvn -Dmaven.repo.local=c:\repo any mvn command
Nirbhay Rana
  • 4,229
  • 2
  • 18
  • 4
0

for maven projects, try to update pom.xml with this.

<properties>
    ....
    <exec.longClasspath>true</exec.longClasspath>
</properties>
-1

Valid answer from this thread was the right answer for my special case. Specify the ORM folder path for datanucleus certainly reduce the java path compile.

https://stackoverflow.com/a/1219427/1469481

Community
  • 1
  • 1
smora
  • 717
  • 5
  • 18
-1

I got the error below when I run 'ant deploy'

Cannot run program "C:\java\jdk1.8.0_45\bin\java.exe": CreateProcess error=206, The filename or extension is too long

Fixed it by run 'ant clean' before it.

maoyang
  • 1,067
  • 1
  • 11
  • 11
-1

I got the same error in android studio. I was able to resolve it by running Build->Clean Project in the IDE.

mhatch
  • 4,441
  • 6
  • 36
  • 62
Kiran
  • 388
  • 2
  • 16
-1

I've had the same problem,but I was using netbeans instead.
I've found a solution so i'm sharing here because I haven't found this anywhere,so if you have this problem on netbeans,try this:
(names might be off since my netbeans is in portuguese) Right click project > properties > build > compiling > Uncheck run compilation on external VM.

Régis B.
  • 187
  • 1
  • 9
-2

This is because of your long project directory name, which gives you a very long CLASSPATH altogether. Either you need to reduce jars added at CLASSPATH (make sure removing unnecessary jars only) Or the best way is to reduce the project directory and import the project again. This will reduce the CLASSPATH. It worked for me.

Deepesh kumar Gupta
  • 884
  • 2
  • 11
  • 29