// 
//     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.
//

= DevFaqNbmPostInstall
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqNbmPostInstall
:description: Apache NetBeans wiki DevFaqNbmPostInstall
:toc: left
:toc-title:
:syntax: true

=== How to specify post-install code in link:NBM.asciidoc[NBM]

link:NBM.asciidoc[NBM] allows to declare its own custom code in link:NBM.asciidoc[NBM] archive. This code is called-back by `Autoupdate/Updater` at the end of installation of link:NBM.asciidoc[NBM] into IDE.

[source,java]
----


your_module.nbm
     |   
     +- Info
     |   |
     |   +--- info.xml
     |
    +- netbeans
        |
        +--- modules...
    |
    +-main
        |
        +--- main.properties
        +--- <custom code>

----

If Autoupdate/Updater detects `main` directory in the NBM archive then `main.properties` descriptor contains information about the own code. `Updater` runs specified Java code according to these properties.

The properties expected in _main.properties_ are:

|===
|Property |Value 

|mainClass |name of the main class, run after module installation from the NBM 

|relativeClassPath |classpath elements, may contain more elements 

|jvm.parameters |properties for JVM, arguments inserted before the main class name 

|mainClass.arguments |more arguments for the main class, added after the main class name 
|===

The run command is built on top of properties above.

link:#1[#1] *Problem*: There was a bug: variable `%IDE_USER%` contained as same value as `%IDE_HOME%` i.e. both links to the platform cluster directory and %IDE_HOME% *didn't* contain user directory as should be. It was fixed in NetBeans 6.5 platform.

The properties can contain several special variables which `Autoupdate` replaces by real values:

|===
|Variable |Value 

|%IDE_HOME% |platform directory 

|%IDE_USER% |user directory link:1.asciidoc[1] 

|%FS% |file separator char 

|%PS% |path separator char 

|%JAVA_HOME% |the current Java home 
|===

==== Example

* Download and unzip a project link:Media:samplepostinstall_DevFaqNbmPostInstall.zip.asciidoc[samplepostinstall_DevFaqNbmPostInstall.zip]
* Go into `samplepostinstall/main` directory
* In `main` directory is main class `Hello` which should use most of possibilities of _post-install_ hooks
* Using properties `mainClass`, `relativeClassPath`, `jvm.parameters` etc.
* Reads all special variables like `%IDE_HOME%`, `%JAVA_HOME%` etc.
* Opens some GUI
* Runs a JDK demo

To see that `samplepostinstall` project in action

1. download link:Media:org-netbeans-samplepostinstall_DevFaqNbmPostInstall.nbm.asciidoc[NBM]
2. run NetBeans IDE (6.0 or newer)
3. invoke _Tools|Plugins_ and switch to _Download_ tab
4. add the downloaded NBM
5. install it and then watch post-install hook what will be executed while installing that plugin

---

_I'm not author of this feature, it's only my investigation._

Do not hesitate to contact me on mailto:jrechtacek@netbeans.org if you have any question.

=== 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/DevFaqNbmPostInstall[http://wiki.netbeans.org/DevFaqNbmPostInstall] , 
that was last modified by NetBeans user Jtulach 
on 2011-07-14T09:51:25Z.


*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.
