1

I following this spring guide on starting gradle. I've installed it and made a build.gradle file with only apply plugin: 'java' in it. When I run gradle build in bash I get the compiled .class files in build/classes/main/hello but when I try to run HelloWorld.class like so: java HelloWorld ...I get the following error... Error: Could not find or load main class HelloWorld.

I'm not that experienced in Java but I have to learn it for school and specifically I have to learn web development but that led me to spring which in turn led me to gradle so I'm just trying to get something to work since nothing seems to be working for me.

*edit:

Here's all the code from the example...

The directory structure:

└── src
    └── main
        └── java
            └── hello

src/main/java/hello/HelloWorld.java:

package hello;

public class HelloWorld {
  public static void main(String[] args) {
    Greeter greeter = new Greeter();
    System.out.println(greeter.sayHello());
  }
}

src/main/java/hello/Greeter.java:

package hello;

public class Greeter {
  public String sayHello() {
    return "Hello world!";
  }
}

The files compile in a different set of folders with the highest level one being build which is in the same directory as src.

I've tried running the command java HelloWorld at every level of the directory structure which includes the folder that contains the .class files.

Sorry if my initial post was vague.

jtht
  • 793
  • 2
  • 10
  • 19
  • please post the exact command line that you use, or explain how you are trying to run it. – Sebastian Aug 20 '15 at 21:11
  • So, you see that the .class file is on `build/classes/main/hello` from where are you trying to run your `java HelloWorld` ? Enter on that path and try to run it – Jorge Campos Aug 20 '15 at 21:16
  • I'm on mac os x using bash, the directory structure is java/build/classes/main/hello and I've tried running the command java HelloWorld in every directory in that hierarchy. – jtht Aug 20 '15 at 21:16
  • @JorgeCampos I've tried it and in every other folder in the hierarchy to no avail – jtht Aug 20 '15 at 21:17
  • I'm trying to make the post better, I don't know why I got a down vote but please ask me for more information if you need it I'm not sure what is needed and what not. – jtht Aug 20 '15 at 21:26
  • Try this: http://stackoverflow.com/a/21360609/460557 – Jorge Campos Aug 20 '15 at 21:31
  • This doesn't have anything to do with Gradle per se. You need to be sure that you have the Java class on the classpath. – Makoto Aug 20 '15 at 21:33
  • ok thanks for trying, I'm trying the stuff from the other link, it's not going well but I guess I'll keep at it. – jtht Aug 20 '15 at 21:49

0 Answers0