NoClassDefFoundError if package name is not equivalent to the physical directory when running Scala Application
If you have a .scala file in the build path that is not in the correct directory compared to the package name.
Example:
Create a Test.scala file and put it in the default package in a source folder and try to execute some code in a package:
Then try to run it as a Scala application and observe:
Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Obviously, it works if you modify the Run configuration to run the a.Test (instead of Test) or if you move it a folder under the source folder called "a"
Example:
Create a Test.scala file and put it in the default package in a source folder and try to execute some code in a package:
package a { object Test extends App }
Then try to run it as a Scala application and observe:
Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Obviously, it works if you modify the Run configuration to run the a.Test (instead of Test) or if you move it a folder under the source folder called "a"
Leave a comment
on 2011-08-09 12:13 *
By Mirco Dotta
Summary changed from Get NoClassDefFoundError if package name is not equivalent to the physical directory to NoClassDefFoundError if package name is not equivalent to the physical directory when running Scala Application
Status changed from New to Accepted
Updated title.
on 2011-08-11 09:14 *
By Mirco Dotta
Eclipse version changed from Indigo to Helios & Indigo
Component changed from None to Eclipse
Milestone set to 2.0
on 2011-09-11 11:49 *
By jhalterman
This also occurs when you run an application in an actual package folder. To recreate, create a package "test" and create an object "Main"
object Main {
def main(args: Array[String]): Unit = { }
}
Right click and run.
java.lang.NoClassDefFoundError: test/Main
Caused by: java.lang.ClassNotFoundException: test.Main
As a workaround, edit the launcher that is created and change the main class from "test.Main" to "Main".
object Main {
def main(args: Array[String]): Unit = { }
}
Right click and run.
java.lang.NoClassDefFoundError: test/Main
Caused by: java.lang.ClassNotFoundException: test.Main
As a workaround, edit the launcher that is created and change the main class from "test.Main" to "Main".
on 2011-11-10 11:13 *
By jhalterman
I'm still getting hit by this on a new project. Any known workarounds?
on 2011-11-10 18:57 *
By nepomuk.seiler
I got the same problem with an Eclipse-RCP-Product.
When I set up a fresh Eclipse IDE installation and start my .product
configuration I got "Mainklasse und nicht gefunden" which isn't really
a exception but says "No main class found".
This is actually surprising, because I have an RCP product.
When I set up a fresh Eclipse IDE installation and start my .product
configuration I got "Mainklasse und nicht gefunden" which isn't really
a exception but says "No main class found".
This is actually surprising, because I have an RCP product.
on 2012-01-31 04:54 *
By skyluc
Version changed from 2.0.0-beta09-29 to 2.0.0-final-29
Assigned to changed from Mirco Dotta to -none-
Component changed from Eclipse to Debugger
Milestone changed from Helium to Backlog
(In revision:0b5f4587aba620857ab0134305469193f5617b54) Made ``Run As Scala Application`` more robust
Display a dialog when trying to run a scala application if:
Fixed #1000911
Branch: master
Display a dialog when trying to run a scala application if:
- The project cannot be built (if that is the case, no binary is produced, hence the application cannot be run).
- The package name doesn't match the source's physical location (this is a known limitation Re #1000541)
- The main type name provided in the Launch Configuration does not point to an existing source.
Fixed #1000911
Branch: master
on 2012-06-18 12:08 *
By Mirco Dotta
(In revision:a1bcb031fba4c2f9b4b23be47619e23a512cc201) Made ``Run As Scala Application`` more robust
Display a dialog when trying to run a scala application if:
Fixed #1000911
(cherry picked from commit 0b5f4587aba620857ab0134305469193f5617b54)
Conflicts:
org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/TestsSuite.java
Branch: release/scala-ide-2.0.x
Display a dialog when trying to run a scala application if:
- The project cannot be built (if that is the case, no binary is produced, hence the application cannot be run).
- The package name doesn't match the source's physical location (this is a known limitation Re #1000541)
- The main type name provided in the Launch Configuration does not point to an existing source.
Fixed #1000911
(cherry picked from commit 0b5f4587aba620857ab0134305469193f5617b54)
Conflicts:
org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/TestsSuite.java
Branch: release/scala-ide-2.0.x
on 2012-06-18 15:21 *
By Mirco Dotta
(In revision:0b5f4587aba620857ab0134305469193f5617b54) Made ``Run As Scala Application`` more robust
Display a dialog when trying to run a scala application if:
Fixed #1000911
Branch: platform/juno
Display a dialog when trying to run a scala application if:
- The project cannot be built (if that is the case, no binary is produced, hence the application cannot be run).
- The package name doesn't match the source's physical location (this is a known limitation Re #1000541)
- The main type name provided in the Launch Configuration does not point to an existing source.
Fixed #1000911
Branch: platform/juno
on 2012-06-26 10:38 *
By Mirco Dotta
(In scala-ide:9f4920ae477d85fa33c738b670cf27355241cde3) Corrected ``MainClassVerifier`` (Re #1001096)
The logic in ``MainClassVerifier`` was partially broken. Indeed, the logic used
for checking that the main unit's package declaration matched its physical
location (rule 3. in the comment) was:
1) plain wrong, and
2) not neeeded because rule 2. was already taking care of it.
Therefore, all code related to rule 3. was removed, and the test provided with #1001096
has been added to the regression suite.
Re #1000541
Fix #1001096
Branch: master
The logic in ``MainClassVerifier`` was partially broken. Indeed, the logic used
for checking that the main unit's package declaration matched its physical
location (rule 3. in the comment) was:
1) plain wrong, and
2) not neeeded because rule 2. was already taking care of it.
Therefore, all code related to rule 3. was removed, and the test provided with #1001096
has been added to the regression suite.
Re #1000541
Fix #1001096
Branch: master
on 2012-06-26 10:46 *
By Mirco Dotta
(In scala-ide:0cd1b9da85ae4d5d045dbb4873973ff8f9031f9b) Corrected ``MainClassVerifier`` (Re #1001096)
The logic in ``MainClassVerifier`` was partially broken. Indeed, the logic used
for checking that the main unit's package declaration matched its physical
location (rule 3. in the comment) was:
1) plain wrong, and
2) not neeeded because rule 2. was already taking care of it.
Therefore, all code related to rule 3. was removed, and the test provided with #1001096
has been added to the regression suite.
Re #1000541
Fix #1001096
(cherry picked from commit 9f4920ae477d85fa33c738b670cf27355241cde3)
Branch: release/scala-ide-2.0.x
The logic in ``MainClassVerifier`` was partially broken. Indeed, the logic used
for checking that the main unit's package declaration matched its physical
location (rule 3. in the comment) was:
1) plain wrong, and
2) not neeeded because rule 2. was already taking care of it.
Therefore, all code related to rule 3. was removed, and the test provided with #1001096
has been added to the regression suite.
Re #1000541
Fix #1001096
(cherry picked from commit 9f4920ae477d85fa33c738b670cf27355241cde3)
Branch: release/scala-ide-2.0.x
on 2012-06-27 13:19 *
By Mirco Dotta
(In scala-ide:9f4920ae477d85fa33c738b670cf27355241cde3) Corrected ``MainClassVerifier`` (Re #1001096)
The logic in ``MainClassVerifier`` was partially broken. Indeed, the logic used
for checking that the main unit's package declaration matched its physical
location (rule 3. in the comment) was:
1) plain wrong, and
2) not neeeded because rule 2. was already taking care of it.
Therefore, all code related to rule 3. was removed, and the test provided with #1001096
has been added to the regression suite.
Re #1000541
Fix #1001096
Branch: platform/juno
The logic in ``MainClassVerifier`` was partially broken. Indeed, the logic used
for checking that the main unit's package declaration matched its physical
location (rule 3. in the comment) was:
1) plain wrong, and
2) not neeeded because rule 2. was already taking care of it.
Therefore, all code related to rule 3. was removed, and the test provided with #1001096
has been added to the regression suite.
Re #1000541
Fix #1001096
Branch: platform/juno
This is fixed in 3.0.1 (if not in 3.0.0 already). The fix simply consists in offering no Run As Scala Application when the source is located in a folder that doesn't match the package declaration.
on 2013-09-06 11:25 *
By Mirco Dotta
This is fixed in 3.0.1 (if not in 3.0.0 already). The fix simply consists in offering no Run As Scala Application when the source is located in a folder that doesn't match the package declaration.
on 2013-09-06 11:25 *
By Mirco Dotta
Fixed in version set to 3.0.1
Version changed from 2.0.0-final-29 to 3.0.1-210
Eclipse version changed from Helios & Indigo to Indigo - Eclipse 3.7