• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I'm having trouble managing my files in Eclipse

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Package Solution(project) with one default package in there. In that default package I have various classes,etc.
When I try to run a class it always runs the first class I put in there.
Is there a way to have multiple classes in the same package but have them run independantly, such that I can test specific classes that aren't related independantly?

Example: I make a Subtraction class first, run it and its works. Then I make a Add class in the same package but when I run it, it always runs the Subtraction class.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey dawud, select the particular java file or class you want to run, than right click on that file you will see a "Run" option select that and it should execte that particular java file. try that
 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I'm trying but it still runs the first class made.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use right-click on the file --> "run..." --> but don't click apply or run yet.

Take a look at the "main class" field to confirm that it is the class that you want to run.

Henry
 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry there is no option to view the class before I select run. I right click then it says "Run As"
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing that may help that I've done is separating them under source folders. Then when I launch I just navigate to the class that I want, right click and run it.
 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea I'm trying the separate folder thing now. The folder default was "src"
but now there is a red x next to it and the class icon. Maybe there is some error or I have to check it out or something first.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think i'm going to move this to the IDE forum.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Have the Java Perspective open, so that Eclipse knows to interpret things in a Java context.

2. In the Explorer view, expand your file list until you see the Java source files you're interested in.

3. Right-click the mouse on the Java source file's name in the Explorer View. A menu should pop up, and one of the options should be "Run as...". Select Java Application to run the application. There's also a "Debug As..." menu option. It acts the same way, except that the class will run under the debugger.

If the class selected does not have a method defined that matches the signature for "public static void main(String[] args)" the class is not executable according to Java's requirements and no action will be taken.

Also, use of the default package is a Bad Thing. Some things just won't work if they aren't in a non-default package. You can create a non-default package using Eclipse (either via the "New/Package" menu option or by creating directories under pn of your project's source directories). Then use the Explorer right-mouse "Move" feature to move the selected Java files into the package directory. Multiple files may be selected at once using the usual GUI conventions.
 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
Some of the classes I wanted to run had no "Run As" option when I right clicked on them, just a Run option. Maybe these didn't have a main in them, I doubt I would over look that, but I'll check.

If I create multiple packages will I be able to implement the classes inside of them exclusively, even in the same Project?
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dawood,

May be this will be helpful.
Select RUN Menu, select Run subMenu

Then you will get a window Run with lot of options in it

In the Main class text feild specify the class file you want to run

Sarath.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sarath",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
reply
    Bookmark Topic Watch Topic
  • New Topic