29

I'm at a complete loss here. I have a project on an external hard drive called LenseProject. Inside LenseProject, I have .idea, lib, Natives and SRC folders. I also have a number of text files for reading.

When I left work last night, this all worked fine. Coming in this morning, I'm met with:

Exception in thread "main" java.lang.ClassNotFoundException: QuadTest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:188)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113) 

QuadTest being the main class.

Information that I think might be helpful:

  • If I comment out the imports, I get the appropriate error messages. (Cannot find symbol, etc).

  • I have 9 dependencies, located in lib\lwjgl-2.9.0\jar that are set up in Project Structure -> Libraries.

  • The module has LenseProject as the content root, and SRC as the source folder.

  • The language level is 7.0

  • I have the dependencies set to export in Project Structure -> Modules -> Dependencies.

  • In Compiler Output, I have it set to Use Module Compile Output Path, as Inherit Project Compile Output Path gave me "Cannot start compilation: The output path is not specified for module "LenseProject". Specify the output path in Configure Project.

  • I have VM option -Djava.library.path=Natives.

  • I can compile and run the program through command prompt no problem.

  • I was missing my configure options when I started it up this morning. I had to set the SDK again, and libraries.

Cereal
  • 3,699
  • 2
  • 23
  • 36

11 Answers11

17

Open your Idea File --> Project Structure --> Modules ,and then choose problematic module,in the "Paths" tab change selected to "Use module compile output path ".

Ky -
  • 30,724
  • 51
  • 192
  • 308
刘新宇
  • 189
  • 1
  • 10
10

I ran into a similar issue while writing unit tests. Everything would work at the command line but failed in IntelliJ. IntelliJ would successfully compile but not run the test.

Then I ran across a post on IntelliJ's blog: http://blog.jetbrains.com/idea/2014/03/intellij-idea-13-1-released/

anet says:

March 21, 2014 at 12:20 pm

You may remove the existing junit dependency and allow IDEA to add JUnit library for your from scratch.

New junit doesn’t bundle hamcrest anymore but still depends on it on runtime.

Thanks, Anna

I removed JUnit from my project settings and let IntelliJ add it back. Then things worked fine.

Community
  • 1
  • 1
TreverW
  • 440
  • 7
  • 16
5

I had similar issue. A new dependency was not being found when running tomcat. The problem was it wasn't being deployed to /WEB-INF/lib. After half a day banging my head on the desk I found this YouTube video that fixed it.

Essentially I needed to add the dependencies from module settings-> artifact->MyWar->Output Layout tab. Under available elements open your projects folder. If there are maven dependencies listed there, select them. Then right click->Put into /WEB-INF/lib

antonkronaj
  • 1,237
  • 12
  • 13
1

In my case, the problem was I reused the "out" directory for program output. I solved it by redirect the output to another folder.

Hao Fu
  • 106
  • 4
0

I suggest confirming your Run Configuration as follows:

Toolbar: Run->Edit Configurations..., confirm your Configuration is correct.

enter image description here

Hope it helps.

Michael
  • 1,667
  • 2
  • 17
  • 18
0

I know its a bit old post but for me helped by going to Run-->Edit Configurations--> In Application Selected your main code file --> Configuration on the right panel. Checked "Use alternative JRE:" and selecting JDK folder called jre(.../Java/jdk.x.x.x_xx/jre). Apply and OK. I am really new with intelliJ but that solved my problem hope it helps someone.

KimasGold
  • 11
  • 2
0

My problem was, that all this renaming the project-structure, my Maven dependencies didn't mach.

After changing the maven dependencies in the pom file, it worked.

Sven Holzinger
  • 103
  • 1
  • 1
  • 9
0

File -> Project Structrure -> Project. Change the Project Language level from "SDK default" to Actual version that you are using.

This is weird, but solves the problem.

Amanpreet Khurana
  • 549
  • 1
  • 5
  • 17
0

Check your mainClassName

mainClassName = "com.xxx.xxxApplicationKt"

Et9
  • 389
  • 3
  • 7
0

After bashing head into multiple times, the issue is resolved by downgrading the Junit version.

At the time of writing the latest junit version is 5.8.2. However, after downgrading the version to 5.7.2 in the pom.xml the test successfully Run.

Resolution 1 : Update Java, if you're using Java 8 check Java version with java -version if Java is added to Path(Windows)

From the Start Menu, and Java Folder, Check for Updates

Resolution 2 : Downgrade junit in pom.xml

Resolution 3 : Install the proper JDK latest version from Oracle link-windows not from Google suggested link

Paul Bradbury
  • 482
  • 6
  • 8
-3

Try going to Preferences -> Compiler and select Eclipse, rather than using javac.

nook
  • 2,378
  • 5
  • 34
  • 54
BAR
  • 15,909
  • 27
  • 97
  • 185
  • So why are you telling Intellij to select the Eclipse compilers? The chances are, they won't be installed. And is it even an option to select them? – Stephen C May 02 '16 at 23:27
  • @StephenC yes, it is an option. Check it out. – BAR May 13 '16 at 15:28
  • 3
    OK ... so assuming that the Eclipse compilers are installed (a stretch!) ... >>why<< would changing the compilers fix what is essentially a runtime classpath problem? – Stephen C May 14 '16 at 00:57