user266538
user266538

Reputation: 1

java project problem

I have a java project. I can run it through command prompt but can not able to run through Eclipse or NetBeans. When I run it, the error come main class is not found.

What can i do ?

Upvotes: 0

Views: 167

Answers (4)

stacker
stacker

Reputation: 68982

A few steps for eclipse

  • create a new project: Menu File/New/Project...
  • place your java source in the src folder of your project
  • through the context menu (right click the project name in navigator) you define the build path, and add required libraries.

  • now your code should be ready to run using the green (>) button

Upvotes: 1

Szyzygy
Szyzygy

Reputation: 106

When you create a project in NetBeans, it will create a default Main class for you, complete with a main(String[] args) method. To access your code, just rename your class main method, copy it (and any dependnt classes into the project and change the package names to reflect the project name) and instantiate the class containing it in the default NetBeans main method and call the renamed main method e.g. if your class is called HelloWorld and the main method was renamed "hello" the call would look like:

HelloWorld hw = new HelloWorld();

hw.hello();

Simples :)

Upvotes: 0

styfle
styfle

Reputation: 24670

Is your project using libraries? I had the opposite problem where I could run my program in Netbeans and not from the jar (or command line) because the libraries were in my Netbeans folder and not my "distribution" folder.

EDIT: By libraries I mean third party libraries.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1502406

How are you trying to run it in Eclipse and Netbeans? Basically you need to tell them which class to execute - which class has the main method in.

In Eclipse you can just go to the relevant class and hit Alt-Shift-X, J to launch it.

Upvotes: 3

Related Questions