Error could not find or load main class org codehaus groovy tools groovystarter

I can't run or debug Groovy scripts in IntelliJ. I'm getting the error: Error: Could not find or load main class org.codehaus.groovy.tools.GroovyStarter. Running scripts from cmd works propertly (I'm

I can’t run or debug Groovy scripts in IntelliJ. I’m getting the error: Error: Could not find or load main class org.codehaus.groovy.tools.GroovyStarter. Running scripts from cmd works propertly (I’m using groovyc and groovy command).

import org.apache.pdfbox.pdmodel.PDDocument
import org.fit.pdfdom.PDFDomTree
import org.w3c.dom.Document

// load the PDF file using PDFBox
PDDocument pdf = PDDocument.load(new java.io.File("file.pdf"))
// create the DOM parser
PDFDomTree parser = new PDFDomTree()
// parse the file and get the DOM Document
Document dom = parser.createDOM(pdf)

asked Jun 8, 2017 at 10:37

Wojtek's user avatar

WojtekWojtek

2331 gold badge4 silver badges16 bronze badges

3

Create Run Configuration (⌘N), and set the Module to the Module that contains all of your dependencies.

See image

answered Jun 11, 2017 at 14:51

Royg's user avatar

RoygRoyg

1,6651 gold badge13 silver badges20 bronze badges

4

I had had the same problem until I did the next:

  1. deleted the groovy from «Global Libraries» (Don’t forget to click the ‘Apply’ button
    screenshot how to delete groovy
  2. Opened any groovy file, and click on «Configure Groovy SDK»
    screenshot how to select groovy
  3. Selected the folder with groovy installation (see on the screenshot above)

After all, I can run/debug my scripts from IDEA

answered Mar 18, 2020 at 16:12

eone's user avatar

1

Try to create you script not as Groovy class.
Use this way:

Ctrl + Shift + A  -> Groovy Script  -> Set script name

answered Jun 8, 2017 at 11:35

Uladzislau Kaminski's user avatar

4

From cboust…@gmail.com on 2013-03-05T06:21:46Z

Hi, thanks for getting back to me.

I have tried as you suggested I have added the bpipe bin folder to my PATH

echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

export PATH=$PATH:/home/chris/Downloads/bpipe-0.9.8_beta_3/bin/
export PATH=$PATH:/home/chris/Downloads/jdk1.6.0_39/bin/
export PATH=$PATH:/home/chris/Downloads/groovy-1.8.9/bin/

echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/chris/Downloads/bpipe-0.9.8_beta_3/bin/:/home/chris/Downloads/jdk1.6.0_39/bin/:/home/chris/Downloads/groovy-1.8.9/bin/

Tried again to run bpipe
bpipe run helloworld.pipe

Exception in thread «main» java.lang.NoClassDefFoundError: org/codehaus/groovy/tools/GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.codehaus.groovy.tools.GroovyStarter. Program will exit.

Which is the same error as before

Any more ideas, am I using the correct java version (jdk1.6.0_39)?

Thanks again for your help

Я не могу запустить или отладить скрипты Groovy в IntelliJ. Я получаю ошибку: Error: Could not find or load main class org.codehaus.groovy.tools.GroovyStarter. Запуск скриптов из cmd работает корректно (я использую команды groovyc и groovy).

import org.apache.pdfbox.pdmodel.PDDocument
import org.fit.pdfdom.PDFDomTree
import org.w3c.dom.Document

// load the PDF file using PDFBox
PDDocument pdf = PDDocument.load(new java.io.File("file.pdf"))
// create the DOM parser
PDFDomTree parser = new PDFDomTree()
// parse the file and get the DOM Document
Document dom = parser.createDOM(pdf)

4 ответа

Лучший ответ

Попробуйте создать свой скрипт не как класс Groovy. Используйте этот способ:

Ctrl + Shift + A  -> Groovy Script  -> Set script name


0

Uladzislau Kaminski
8 Июн 2017 в 11:35

Создайте Run Configuration (⌘N) и установите Module для модуля, который содержит все ваши зависимости.

See image


3

Royg
12 Июн 2017 в 15:54

#java #groovy

Вопрос:

Я пытаюсь установить Groovy в Windows 10 вручную. И я продолжаю получать следующую ошибку. Ошибка: Не удалось найти или загрузить основной класс org.codehaus.groovy.tools.GroovyStarter Вызвано: java.lang.Исключение ClassNotFoundException: org.codehaus.groovy.tools.Устройство для нарезания канавок

То, что я сделал, это:

 C:WINDOWSsystem32>Setx JAVA_HOME "C:Program FilesJavajdk-13.0.2"

SUCCESS: Specified value was saved.

C:WINDOWSsystem32>echo %java_home%
C:Program FilesJavajdk-13.0.2

C:WINDOWSsystem32>Md "C:Program Files (x86)Groovy"

C:WINDOWSsystem32>move "C:tempgroovy-3.0.7" "C:Program Files (x86)Groovy"

C:WINDOWSsystem32>Setx GROOVY_HOME "C:Program Files (x86)Groovygroovy-3.0.7src"

C:WINDOWSsystem32>set PATH="C:Program Files (x86)Groovygroovy-3.0.7srcbin";%PATH%
 

И когда я набираю «groovysh»,

 C:WINDOWSsystem32>groovysh
Error: Could not find or load main class org.codehaus.groovy.tools.GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
 

Я не уверен, что я пропустил.

Буду очень признателен, если кто-нибудь укажет на мою ошибку.

Спасибо.

Комментарии:

1. Откуда у тебя эта классная папка? Если вы скачали его с github, вам придется запустить загрузочную версию gradle перед его использованием

2. Привет, я скачал его с groovy-lang.org/install.html и выберите «Исходный релиз».

3. Я думаю, вам следовало выбрать двоичный выпуск, в который будут включены все эти файлы

4. Спасибо вам за комментарий. Мне интересно, в чем разница между двоичным выпуском и исходным выпуском.

5. Исходный релиз-это буквально исходный код для Groovy. Если вы хотите использовать его, вы должны собрать/скомпилировать его, что не для новичков. Это то, что означает открытый исходный код. Если вы просто хотите, чтобы мы это сделали, скачайте двоичный выпуск. Получите установщик Windows 3.0.8 здесь

Hi,

I’m running JAFFA with my own data,and I got some problems.

I installed groovy ,and type groovy —version , it shows Groovy Version: 2.5.8 JVM: 1.8.0_65 Vendor: Oracle Corporation OS: Linux

Then I run the script ./install_linux64.sh as suggested and showed All commands installed successfully!

when I run /home/software/JAFFA-version-1.09/tools/bin/bpipe run /home/software/JAFFA-version-1.09/JAFFA_direct.groovy /home/data/sample01*.gz, it showed 

Error: Could not find or load main class org.codehaus.groovy.tools.GroovyStarter

I used groovy to debug: groovy -d /home/software/JAFFA-version-1.09/JAFFA_direct.groovy

    Caught: groovy.lang.MissingPropertyException: No such property: bpipe for class: JAFFA_direct

    groovy.lang.MissingPropertyException: No such property: bpipe for class: JAFFA_direct

        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65)

        at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51)

        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309)

        at JAFFA_direct.run(JAFFA_direct.groovy:12)

        at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)

        at groovy.lang.GroovyShell.run(GroovyShell.java:376)

        at groovy.lang.GroovyShell.run(GroovyShell.java:365)

        at groovy.ui.GroovyMain.processOnce(GroovyMain.java:592)

        at groovy.ui.GroovyMain.run(GroovyMain.java:336)

        at groovy.ui.GroovyMain.access$1400(GroovyMain.java:69)

        at groovy.ui.GroovyMain$GroovyCommand.process(GroovyMain.java:295)

        at groovy.ui.GroovyMain.processArgs(GroovyMain.java:134)

        at groovy.ui.GroovyMain.main(GroovyMain.java:116)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:497)

        at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:110)

        at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)

I wonder how to solve this, thanks a lot.

This bug affects 1 person

Affects Status Importance Assigned to Milestone


groovy (Ubuntu)

Fix Released

High



James Page

Ubuntu ubuntu-12.04-beta-2

Precise

Fix Released

High



James Page

Ubuntu ubuntu-12.04-beta-2

Bug Description

Attemps to start groovysh end with the following Java stack trace:

Exception in thread «main» java.lang.NoClassDefFoundError: org/codehaus/groovy/tools/GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.codehaus.groovy.tools.GroovyStarter. Program will exit.

Exit code is 1.

This is a regression from Oneiric (where groovysh starts as expected). Groovy 1.8.6 (in Debian Testing) also behaves as expected.

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: groovy 2.0.0~beta2+isreally1.8.5-0ubuntu1
ProcVersionSignature: Ubuntu 3.2.0-18.29-generic 3.2.9
Uname: Linux 3.2.0-18-generic x86_64
ApportVersion: 1.94.1-0ubuntu2
Architecture: amd64
Date: Mon Mar 12 18:03:21 2012
InstallationMedia: Ubuntu 11.10 «Oneiric Ocelot» — Alpha amd64 (20110802.1)
PackageArchitecture: all
ProcEnviron:
 TERM=xterm
 PATH=(custom, user)
 LANG=en_US.UTF-8
 SHELL=/bin/zsh
SourcePackage: groovy
UpgradeStatus: No upgrade log present (probably fresh install)

Related branches

The Java “Could not find or load main class” error is thrown when the JVM fails to find or load the main class while executing a program. It usually occurs when executing a Java program from the command line.

Install the Java SDK to identify and fix these errors

What Causes Error: Could not find or load main class

The «Could not find or load main class» error occurs when the JVM fails to load the main class. This can happen due to various reasons, such as:

  • The class being declared in the incorrect package.
  • The file path of the class not matching the fully qualified name.
  • Incorrectly specified classpath of the application.
  • Missing dependencies from the classpath.
  • Incorrect directory path on the classpath.
  • A typo in the class name.

Error: Could not find or load main class Example

Here’s an example of the Java «Could not find or load main class» error thrown when an incorrect class name is specified during execution:

Here’s an example Java class MyClass.java:

public class MyClass {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Now the above class is compiled using the command line:

$ javac MyClass.java

The compiler generates an executable .class file for MyClass:

$ ls
MyClass.class   MyClass.java

Now if the java command is used to execute the .class file with an incorrect name, the «Could not find or load main class» error is thrown:

$ java Myclass
Error: Could not find or load main class Myclass

The generated .class file has the exact same name as the Java class, which in this case is MyClass.class. Specifying the correct name will execute the program successfully:

$ java MyClass
Hello World

How to Fix Error: Could not find or load main class

There are several ways the «Could not find or load main class» error can occur while executing Java programs. Most of the time, it occurs because of specifying an incorrect class name, class file extension, file path or classpath.

The following tips can be useful to resolve the «Could not find or load main class» error:

  • Using correct class name — The spelling and casing of the class name should be checked when executing the program.
  • Using the class name without the .class extension — The java command expects the class name for executing the program, without the .class extension. Therefore, the following syntax should be used to execute Java classes: java <classname>
  • Using the correct file path — The path to the .class file should be checked and corrected if the error occurs. Remember to use the fully qualified name of the class that is in a package if executing it from outside the directory structure of the package.
  • Correct classpath definition — The classpath should be checked and defined correctly if the error comes up. It can also be specified using the java -cp or -classpath command line arguments.

Track, Analyze and Manage Errors With Rollbar

Managing errors and exceptions in your code is challenging. It can make deploying production code an unnerving experience. Being able to track, analyze, and manage errors in real-time can help you to proceed with more confidence. Rollbar automates error monitoring and triaging, making fixing Java errors easier than ever. Sign Up Today!

Понравилась статья? Поделить с друзьями:
  • Error could not find or load main class net minecraft client main
  • Error could not find or load main class myfirstapp class
  • Error could not find or load main class misc tweaker stubmain
  • Error could not find or load main class main maven
  • Error could not find or load main class main intellij idea