0

I'm trying to run a project in Netbeans, but I'm running into some major problems. When I build project (F11) it creates a jar file instead of simply creating classes, and I'm unable to run the project because no classes were found. I suspect it might be because I added a jar file as a library.

Anyway, when I build the program it tells me to run it from command line by using java -jar program.jar. So I try that and I get Error: Could not find or load main class something.java. In project properties correct class is chosen to be a main class.

Help would be much appreciated!

querti
  • 77
  • 2
  • 8
  • You need your project settings to use (ex: main.java) as the main file. You should find a setting like that in the project settings. – Evan Carslake Mar 28 '16 at 16:21

1 Answers1

0

The error:

Error: Could not find or load main class something.java

Is looking specifically for a method public static void main(String args[])

Does that exist in any of your classes?

Netbeans will automatically compile class files on the fly when saving a source file.

ed:

To run a JUnit test, see this answer:

https://stackoverflow.com/a/7172646/288915

Community
  • 1
  • 1
kevingreen
  • 1,541
  • 2
  • 18
  • 40
  • Hmm it doesn't, but the problem is that I didn't create that class and it is supposed to be used to test if my program works correctly (using assert) – querti Mar 28 '16 at 14:14
  • 1
    To "run" a program, the program has to have a starting point. That is always `public static void main(String args[])`. Without that, there is not starting point, and therefore the program will fail to do anything. – Rabbit Guy Mar 28 '16 at 14:16
  • @mandatory . If you're using "assert" are you using a testing library, like JUnit? There needs to be a "beginning" for the JVM to start at. – kevingreen Mar 28 '16 at 14:19
  • Yes I am using junit. Could that explain why there is no main? – querti Mar 28 '16 at 14:22
  • 1
    @mandatory You need to call JUnit differently than a regular "jar" execution. See this answer: http://stackoverflow.com/a/7172646/288915 – kevingreen Mar 28 '16 at 14:24