2

I am doing a Java project in Eclipse on Windows. I implemented some methods and tried to test them. But, in Eclipse run or run as seem to be empty.

When I try to right click to my project on package explorer and choose run as Java Application, a pop-up shows up and says Select Java Application. But the list under it looks like completely strange to me. And in the same pop-up, at the bottom there is a package name which is not my projects's package. Actually it is exactly the same package where I copied some methods with copy paste. (I changed them in my project). But it seems to be run settings somehow became default or something.

This is a school hw and my teacher gave me some files with method definitions. I created a project in Eclipse and copied the files into src folder.

So, the question is, how can I change this and run my own project? Thanks in advance...

NOTES: My project is a Java project. I am trying to connect from Eclipse to MySQL using JDBC and run some queries. Connector jar file is on place. Path settings seem to be right.

EDIT: My teacher wants me to implement an interface named ICPL. So I created a java file named CPL. My teacher also gave me a separate Main.java file.

main function class path run config main source

kalahari
  • 895
  • 5
  • 15
  • 34
  • What type of project did you create? do you have a class with a main method in it? – A4L Nov 01 '14 at 19:28
  • 1
    Thank you for reply. I write an edit at the bottom of question. – kalahari Nov 01 '14 at 19:37
  • 1
    If the class `Main` contains a method `public static void main(String[] args) { ... }` then you can right click on it (either in the package explorer or in the java editor view) and choose run as java application. – A4L Nov 01 '14 at 19:42
  • It contains, but when I right click, there is no run. – kalahari Nov 01 '14 at 19:45
  • Also, when I try to make a new configuration, in main part, there is nothing written. I clicked the search, and typed **, all of the list is belong to the wrong package, how can I define my package to this configuration? – kalahari Nov 01 '14 at 19:49
  • That's strange, are you sure you are in the right perspective? can you share a screenshot of your eclipse with the project in it? – A4L Nov 01 '14 at 19:59

3 Answers3

1

Make Sure:

  1. you are working on the Jave Perspective . There are various prespective in Eclipse.
  2. when you created your project, have u selected file>new>Java Project.
  3. right click on you project in project explorer,then choose run configuratin,in the "type filter text" text box type "java application" ,select it and choose prespective link on the right side.
  4. select Java Application in "Application Type/Launchers:" list box. Then select "Java" in "Run" drop down box.

  5. apply>ok

  6. here you go.
AsSiDe
  • 1,826
  • 2
  • 15
  • 24
  • Thanks, I did these. I think the problem is that Eclipse can't find my Main.java. In run configuration, what should I write in Main Class part? I use a package named ceng.ceng351.cpl. – kalahari Nov 01 '14 at 20:07
  • in your Main.java file ,you must have to define main(String[] args ) method and call those methods you had given. – AsSiDe Nov 01 '14 at 20:11
  • No no, that part is like you said. I asked for "run configuration" part. – kalahari Nov 01 '14 at 20:13
  • right click on your package inside your project.select Refactor>rename.provide new name "ceng" ,ok>update references. – AsSiDe Nov 01 '14 at 20:25
  • Package's name should be "ceng.ceng351.cpl". Thats a must. – kalahari Nov 01 '14 at 20:27
  • in your new configuration dialog box type "ceng.ceng351.cpl.Main.java" in your "Main Class:" Text Box – AsSiDe Nov 01 '14 at 20:32
  • I did it and get this error "Error: Could not find or load main class ceng.ceng351.cpl.Main.java" – kalahari Nov 01 '14 at 20:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/64094/discussion-between-ashish-singh-dev-and-kalahari). – AsSiDe Nov 01 '14 at 20:34
0

Do you have main method? Try Run - Run Configurations - Java Application and create new launch configuration.

nikoliazekter
  • 757
  • 2
  • 6
  • 23
0

Right click on the class that contains the main method and the use Run as Java application.
Or when you click on the project and have that multiple choice check for the class with a main method.

Great eclipse tutorial for beginners:
http://eclipsetutorial.sourceforge.net/workbench.html
http://eclipsetutorial.sourceforge.net/totalbeginner.html
http://eclipsetutorial.sourceforge.net/persistence.html
http://eclipsetutorial.sourceforge.net/debugger.html

Mladen Uzelac
  • 1,173
  • 1
  • 10
  • 14