0

Using Java8, Eclipse Mars 4.5 I have a simple Maven project with a pom and a single java file, in a folder. I do the File -> Import -> Existing Maven Project -> Point to my folder. Eclipse does its thing sucessfully creates the project (no errors). But with somewhat of a complex folder structure that I am able to edit (with some difficulty). My project file structure is:

 Project
     /classes
       /pkg
        /.class
     /src
      /pkg
       /.java

I originally see my java file (but not in the /src), I see all my dependent jars. After some doing (open/new etc) I am able finally compile my java class- I see all the generated class files. But I am unable to run it. I do have my main class specified in the eclipse run configuration. I don't have the Run As enabled. I try run java application, get error:

Could not find or load main class 'myclass' (I do have the main method)

If I try Maven build (M2 the red icon), initially I got 'no goal specified' error, added <defaultGoal>install</defaultGoal> to the pom. I do get BUILD SUCCESS

But still no run? What am I missing. I went the maven project route to simplify, but

Thanks

Sam-T
  • 1,877
  • 6
  • 23
  • 51
  • 1
    Possible duplicate of [how to setup "Main Class" in "Run Configurations" in Eclipse](http://stackoverflow.com/questions/17397440/how-to-setup-main-class-in-run-configurations-in-eclipse) – andolsi zied Dec 06 '16 at 15:12
  • @andolsi zied - I do have the main class specified in my eclipse run configuration – Sam-T Dec 06 '16 at 15:22
  • Can you share the `pom.xml` ? – Shmulik Klein Dec 06 '16 at 20:19
  • @ Shmulik Klein My pom is very simple, it just has ` - jar files`, no src. In `` it simply has ` maven`. I don't know if I messed the default file structure of eclipse/maven that is causing the problem - I edited that to create what I have shown in the question. – Sam-T Dec 06 '16 at 21:49

1 Answers1

1

This problem was finally solved by conforming (submitting) to the default file structure of the eclipse/maven project- <classpathentry kind="src" output="target/classes" path="src/main/java">. I re-created the file structure (as this) put/copied my .java and .classes in those directories - it ran fine finally.

I could see this problem when I opened the .classpath file - it had the original /classes and /src directory and not he one I had edited in eclipse (as I indicated in my Question). Even though I was actually successfully compiling into my /classes. I would certainly not expect this behavior, there is clear edit option for /src and /classes and it should take effect- but maybe not.

Another observation to add- when I look at my run configuration - I see the correct class but eclipse does not show the location. So one would never know.

So long story short it finally worked after much frustration and effort and loss of a couple of days (And I just had exactly one java file to compile and run - wondering how much pain would be if I had a few more).

I am not a regular eclipse user (any longer) so some of it would be getting used to etc - but some of these quarks need to be taken care of (It is the No1 tool)

Sam-T
  • 1,877
  • 6
  • 23
  • 51
  • With your previous folder structure, how could Maven find the sources? Maybe the "successful" Maven build just did nothing? And then, if the pom has no indication of non-standard folders, then the Maven integration in Eclipse has little chance to figure out your intention, I guess. – Stephan Herrmann Dec 07 '16 at 20:53
  • My pom had no dir structure at all, just dependency. That is fine- if maven didn't build it is OK. I recreated/edited the default dir structure in eclipse- so eclipse should work- but it did not. Eclipse was creating in the new structure but unable to execute from that. (disconnect within eclipse) – Sam-T Dec 07 '16 at 21:18
  • Something sounds contradictory, here. I'm still not 100% sure what was the original folder structure of your project before import into Eclipse plus "editing"? You basically have two options: conform to conventions (in Maven: `src/main/java` + `target/classes`) *or* tell your tools what you want (in Maven: by specifying these directories in your pom). You don't seem to do either, which causes unnecessary confusion to the tool and yourself. – Stephan Herrmann Dec 08 '16 at 01:08