| // |
| // 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. |
| // |
| |
| = DevFaqModuleDependencies |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| :keywords: Apache NetBeans wiki DevFaqModuleDependencies |
| :description: Apache NetBeans wiki DevFaqModuleDependencies |
| :toc: left |
| :toc-title: |
| :syntax: true |
| |
| === How do module dependencies and class loading work? |
| |
| The nuts and bolts of module dependencies are as follows: |
| |
| * Modules can load classes from modules they depend on. They have to declare a dependency on them. |
| * NetBeans does not care about things like the `CLASSPATH` environment variable - it knows how to find modules in an installation of NetBeans, and enforces dependencies between them. |
| |
| What this means is that if |
| |
| * Module B tries to use a class from module A, but module B does not _explicitly state_ that it depends on A, or... |
| * Module B tries to use a class from module A, and it _does_ declare a dependency on Module A, _but_ the package that class is in is not in the list of packages A says other modules can touch... |
| |
| then a `NoClassDefFoundException` will be thrown at runtime. |
| (If you even get that far - the module build harness will refuse to even compile module B in such cases.) |
| |
| An exception to the second item is that if Module B declares an _implementation dependency_ on module A, then it will have access to the full set of classes. |
| Normally you should not need to do this, |
| and anyway it will then be hard to upgrade B independently of A. |
| |
| Modules can also load classes from libraries - JAR files that are packaged with the module (see link:DevFaqHowPackageLibraries.asciidoc[DevFaqHowPackageLibraries]). |
| Some points to remember about libraries: |
| |
| * They are delivered to the user inside the NBM file if they are not part of a full application based on NetBeans. |
| * When unpacked, the module will end up in `$SOMECLUSTER/modules/` and any libraries will end up in `$SOMECLUSTER/modules/ext/`. |
| * The module will use the library by having an entry in its manifest `Class-Path: ext/someLibrary.jar` the same way any JAR would. |
| |
| If you are using the IDE's module development support, |
| you will manage module dependencies in the properties dialog for your module |
| (or the *Libraries* node in the *Projects* tab). |
| This just modifies `yourmodule/nbproject/project.xml`. |
| The data saved there is then used to generate the appropriate manifest entries for you. |
| |
| If you are writing a module that will use some third party libraries, |
| you probably want to read link:DevFaqWrapperModules.asciidoc[DevFaqWrapperModules] and also link:DevFaqWhenUseWrapperModule.asciidoc[DevFaqWhenUseWrapperModule]. |
| |
| For more details, see the link:http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html[reference documentation about classloading in NetBeans]. |
| |
| <hr/> |
| |
| Applies to: NetBeans 6.8 and above |
| |
| === 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/DevFaqModuleDependencies[http://wiki.netbeans.org/DevFaqModuleDependencies] , |
| that was last modified by NetBeans user Rmichalsky |
| on 2009-12-02T13:40:56Z. |
| |
| |
| *NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed. |