3

Before you mark this as a duplicate, please hear me out.

I am trying to import a java project with gradle(Fully functional, works for every other laptop with no issues).

  1. My project is 100% functional, it works on every other laptop

  2. This issue started when my laptop was reimaged an set as windows 10

  3. I have configure the Environment variables, JAVA_HOME = C:\Program Files\Java\jdk1.8.0_161, in PATH I've added C:\Program Files\Java\jre1.8.0_161\bin

  4. Command line I am seeing the correct version. (Java -version)

  5. I right clicked my project "configure build path". I ensured that it is the latest version I mentioned in my environment variable (1.8.0_161).

  6. I've imported my project, clean build, refreshed and ran (shows Cannot find or load main class)

  7. In the command line, I did gradle clean build builds successfully with no error

  8. I also ran my java application java -jar app.jar My applications starts up and runs on localhost:8080

  9. I created a test project a simple hello world, and it is running with no issues.

So, My question stands what is causing this cannot load main class error in ECLIPSE and in Spring tools suite IDE?

PS: I do not have any misconfigure packages(as I mentioned project works perfectly find on any other laptop) Also, I have deleted Eclipse(.p2, .eclipse, eclipse and eclipse workspace folder), Java, and gradle and reinstalled all of the multiple times.

UPDATE

As mentioned above (#8) it will work if I run the .jar application.

I also tried running my java application thru command prompt

java C://.......myMainApp.java

Error: Could not find or load main class com.jesse.umsswap.app.myMainApp

Edit not duplicated

As I mentioned in this post, The two links provided by Jarrod did not resolve my issue. I have gone thru those two post and the solutions did not solve mine.

PS

Have you ever had a working java project in git, but when you cloned it is saying "cannot load or find main class"?

JayC
  • 2,144
  • 8
  • 42
  • 77
  • Whats your main class configured in `Run>Run Configurations>(name)>Main>Main class`? – sn42 Apr 09 '18 at 17:19
  • @sn42 it is pointing to my main class – JayC Apr 09 '18 at 18:06
  • Is it possible that you share your launch configuration (`/.metadata/.plugins/org.eclipse.debug.core/.launches/.launch`)? – sn42 Apr 09 '18 at 18:26
  • @sn42 It has 1 file. myMainApp.launch (1kb) – JayC Apr 09 '18 at 18:31
  • I am facing exactly same issue but with maven project – Monika Apr 09 '18 at 18:35
  • The SSLHandshakeException *may* be related to some corrupted gradle wrapper files, see [this post](https://discuss.gradle.org/t/gradle-1-12-wrapper-fails-unable-to-find-valid-certification-path-to-requested-target/2079). Are you required to use Gradle 2.12? – sn42 Apr 09 '18 at 18:52
  • @sn42 my project needs 2.12 or 2.13 gradle. But command line gradle is working perfectly fine? – JayC Apr 09 '18 at 19:07
  • 1
    You used the `gradle` command to build your project, while eclipse uses your project local `./gradlew` command. Maybe that messed it up? – sn42 Apr 09 '18 at 19:13
  • @sn42 your correct looks like my gradle wrapper is messed up. Let me try to create a new wrapper see if this resolves. – JayC Apr 09 '18 at 19:34
  • @Jesse Don't forget to refresh your gradle project after you setup the gradle wrapper. – sn42 Apr 09 '18 at 19:37
  • @sn42 I removed the "s" from https in gradle wrapper properties file. fixed the gradle refresh issue. But main class is still cannot be found or load. – JayC Apr 09 '18 at 19:49
  • 1
    @Jesse if `./gradlew clean build` gives no errors, the resulting app can be run successfully and your Gradle wrapper is fine now, maybe reimporting the project to eclipse (as a Gradle project, -> buildship) may result in finding the main class. My thoughts: Gradle is fine then, you describe other eclipse gradle projects work -> delete projects run config and all eclipse files (`.settings`, `.project`, ...). I know this is an invasive step, but if you say other fresh eclipse projects work, why not make your project a fresh one too? Does this help you? – sn42 Apr 10 '18 at 14:21
  • @sn42 Yes, this actually resolved the issue, gradle clean build, ./gradlew clean build. reimport project and it's working. Thank you so much! – JayC Apr 10 '18 at 14:35
  • @Jesse Do you mind if i post this comment as an answer and you accept it? Would be beneficial to readers not to skip through all of our comments + gives me some guicy points :P – sn42 Apr 10 '18 at 14:38
  • 1
    @sn42 Of course I don't mind! I'll accept your answer. Thank you for taking your time to assist me on this issue! – JayC Apr 10 '18 at 14:44
  • @sn42 I tried to replicate the same steps I did for this project. I got a new project from the git. did the gradle clean and gradlew clean but now it's back to main class cannot be load or found, once again. – JayC Apr 10 '18 at 15:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168659/discussion-between-sn42-and-jesse). – sn42 Apr 10 '18 at 15:47

1 Answers1

1

If ./gradlew clean build gives no errors, the resulting jar can be run successfully and your Gradle wrapper is fine (see question comments for more info), maybe reimporting the project to eclipse (as a Gradle project, -> buildship) may result in finding the main class

My thoughts: You ensured that your gradle build is working and other gradle projects within the same worksace are functional too. Then the next logical step is to work with a fresh copy of your project: Re-import it.

After closing eclipse delete all eclipse related files (.settings, bin, .classpath, .project) as well as the run configuration you used to start the application. Make sure you back it up or know all infos to recreate it (vm args, environment vars for your run config).

I know this is an invasive step, but if you say other fresh eclipse projects work, why not make your project a fresh one too?

sn42
  • 2,353
  • 1
  • 15
  • 27
  • Steps taken to solve this issue. 1) Clean project 2) Refresh Project 3) Gradle refresh 4) Close Eclipse 5) Reopen and Rerun Application – JayC Aug 08 '18 at 20:37