Intellij Cannot resolve symbol on import

This problem happens intermittently for different libraries and different projects. When trying to import a library, the package will be recognized, but the class name can’t be resolved. If on the import statement, I right-click -> Goto -> the package’s declaration, I see all the decompiled classes displayed in the side pane — Including the … Read more

How to add directory to classpath in an application run profile in IntelliJ IDEA?

I’m trying to add a directory to the classpath of an application run profile If I override by using -cp x:target/classes in the VM settings, I get the following error: java.lang.NoClassDefFoundError: com/intellij/rt/execution/application/AppMain Any idea on how to add a directory to the classpath for my project? 8 Answers 8

Get a list of resources from classpath directory

I am looking for a way to get a list of all resource names from a given classpath directory, something like a method List<String> getResourceNames (String directoryName). For example, given a classpath directory x/y/z containing files a.html, b.html, c.html and a subdirectory d, getResourceNames(“x/y/z”) should return a List<String> containing the following strings:[‘a.html’, ‘b.html’, ‘c.html’, ‘d’]. … Read more

What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?

What is the difference between NoClassDefFoundError and ClassNotFoundException? What causes them to be thrown? How can they be resolved? I often encounter these throwables when modifying existing code to include new jar files. I have hit them on both the client side and the server side for a java app distributed through webstart. Possible reasons … Read more

How to really read text file from classpath in Java

I am trying to read a text file which is set in CLASSPATH system variable. Not a user variable. I am trying to get input stream to the file as below: Place the directory of file (D:\myDir)in CLASSPATH and try below: InputStream in = this.getClass().getClassLoader().getResourceAsStream(“SomeTextFile.txt”); InputStream in = this.getClass().getClassLoader().getResourceAsStream(“/SomeTextFile.txt”); InputStream in = this.getClass().getClassLoader().getResourceAsStream(“//SomeTextFile.txt”); Place full … Read more