| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| |
| = DevFaqNoClassDefFound |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| :keywords: Apache NetBeans wiki DevFaqNoClassDefFound |
| :description: Apache NetBeans wiki DevFaqNoClassDefFound |
| :toc: left |
| :toc-title: |
| :syntax: true |
| |
| === My module uses some class from NetBeans' APIs. It compiles, but I get a NoClassDefFoundError at runtime. Why? |
| |
| Normally this should not happen because the module build harness tries to protect you from such cases. Still, if it does happen, it could mean |
| |
| 1. your module is trying to use a class, but your module does not declare a dependency on the module that provides that class ... or |
| 2. you are declaring a dependency on the right module, but you are accessing a class that is not in one of the packages that module says are public (for use by other modules) ... or |
| 3. your module is not a "friend" of the module that provides the class. |
| |
| If the problem is #1, you need to declare a dependency on the module where the class is (remember that all of NetBeans APIs are modules, and in separate jars - so if it's the IO API, that's a module `org.openide.io`, if it's the Window System, that's a module `org.openide.windows`... and so forth). |
| |
| Setting dependencies is easy - open the *Properties* for your project, and choose the *Libraries* page. (Or just get the context menu for the *Libraries* node under the project in the *Projects* window.) Click *Add* and a small dialog opens - just type the name of a class you need to use, and it will filter the list to find the module that provides that class - so you don't have to memorize a huge list of mappings from classes to modules. |
| |
| If it's problem #2, then you are already declaring a dependency, but to get full access to all classes in a module, you need to declare an implementation dependency (link:DevFaqImplementationDependency.asciidoc[DevFaqImplementationDependency]). |
| Be sure you _really_ need to use the class you're trying to use, in this case - it will make your module hard to upgrade because generally it will need to be paired with the exact version of the other module's JAR that it was built with - if that module is upgraded, your module may end up being disabled. |
| |
| Also check if class you are trying to use from other module is mark as public to outside modules (right-click on module and select _Properties_, then _API Versioning_ and in _Public Packages_ check whether package of your class is ticked). |
| |
| Problem #3 may happen if you change your modules name. If some module declared yours as a friend |
| it will no longer recognize it. |
| |
| ==== Checking for errors eagerly |
| |
| For a nice way to resolve all module dependencies at once, to force all of the errors to be exposed simultaneously, just add the following to the command line when starting NetBeans: |
| |
| `-J-Dnetbeans.preresolve.classes=true` |
| |
| The message displayed states that when using this flag, you should _not_ use the `-J-Xverify:none` flag (often specified in the IDE configuration file), so you may need to edit the `.conf` file to remove the -Xverify option before using the pre-resolve option. |
| |
| ==== More tips |
| |
| For help on working with class paths, please see |
| |
| link:http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html[http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html] |
| |
| Applies to: NetBeans 6.x |
| |
| Platforms: all |
| |
| === Apache Migration Information |
| |
| The content in this page was kindly donated by Oracle Corp. to the |
| Apache Software Foundation. |
| |
| This page was exported from link:http://wiki.netbeans.org/DevFaqNoClassDefFound[http://wiki.netbeans.org/DevFaqNoClassDefFound] , |
| that was last modified by NetBeans user LiborJelinek |
| on 2011-08-19T08:08:17Z. |
| |
| |
| *NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed. |