In the Part3, we have seen how to create a web application bundle(WAB) and deploy it into Glassfish.
Since I have mentioned "deployment", in this part, I will make a priority description for how to deploy an OSGi Application into Glassfish.
Why? Maybe you can ask me why not continuing to look into WAB or EJB bundle's implementation mechanism in depth?
The reason is as following:
1) all inside info about Glassfish OSGi-JavaEE start from deployment, or saying, deployment is the next parts's bootstrap point.
2) Glassfish OSGi-JavaEE Application deploying process is a glue between Glassfish JavaEE containers and pure OSGi context, without the glue, we can not continue our story.
So, I will introdue Glassfish OSGi-JavaEE's deployment in this Part and Part5. In this Part, I will introduce the ways of deploying an OSGi Application into Glassfish; And in the Part5, I will bring you an looking into the backend of deploying an OSGi Application in depth.
As far as I know, there are three ways of deploying an OSGi Application into Glassfish.
1. using "asadmin deploy --type=osgi"
eg. for a WAB(assuming we call it "helloworldwab") which has been built, we can use the following command to deploy it,
>asadmin deploy --type=osgi /.../.../helloworldwab-1.0-SNAPSHOT.war
If deploying successfully, you will see the following similar image.
Noting: we must add "--type=osgi" option, otherwise, you am deploying a common war rather than wab. I have seen many such errors in glassfish jira.
The command will cause the following results:
1) the wab is expanded into default domain's applications directory
Just as common JavaEE deployment, the wab is also expanded into glassfish default domain's applications directory, eg. in my enviroment, a helloworldwab-1.0-SNAPSHOT directory is generated under domain1/applications
Noting: the above deployment command has not specified --target, so defaultly, this will deploy the wab in default domain's server instance.
2) the wab related configuration info is written into default domain's domain.xml
Apart from generating a helloworldwab-1.0-SNAPSHOT directory, the wab related configuration info is also written into default domain's domain.xml. Eg. in my enviroment, the added wab info is as following:
The behavior means that the wab has been in the management context of glassfish admin infrustructure. Eg. the management context can do the following for the wab later,
- while the whole system is in cluster mode, the WAB will enjoy the capabilities which glassfish cluster brings. (About the point, I need to confirm deeply and once having any result, I will write a seperate part for it)
3) default domain's osgi-cache will generate the wab's bundle revision info
You can see the generated wab's bundle revision info by entering glassfish4\glassfish\domains\domain1\osgi-cache\felix\
There is more quick and easy way to see current deployed bundles info in current Glassfish v4. You can execute the following command:
>asadmin osgi lb
The above result displayed that our helloworldwab has been installed and started successfully, and it has a bundle id called "293", state is "Active".
You may be curious why bundle id is 293 rather than 290?
OK, this is because after you deployed a bundle(id=290) then undeployed the bundle, if you deployed the bundle again, then, the bundle id will be 291, so I must do several times back and force, :)
By the way, "asadmin osgi lb" can list many installed bundles info, so if you know some bundles's keyword and want to find these bundles's bundle id quickly, you can use the following:
>asadmin osgi lb | grep HK2 (linux/unix)
or
>asadmin osgi lb | findstr HK2 (windows)
2. dropping the wab into "autodeploy\bundles\" directory
This is also called autodeploying mode. This is very convenient and Sahoo has an outstanding article about the autodeploy mode.
3. using "asadmin osgi install" command
Although I do not encourge to use the way, I still need to mention it. For my wab, I can use the following command,
>asadmin osgi start file:///E:/glassfishdev/readworldosgijavaee/helloworldwab/target/helloworldwab-1.0-SNAPSHOT.war
If you do not start the bundle immediately while deploying the wab, you only use "asadmin osgi install ....".
So far, you maybe ask me the difference among the above three ways and how I should use them rightly?
Basiclly, My consideration is as following:
"asadmin deploy --type=osgi" command is very orthodox, and is borned for glassfish osgi-javaee :)
In most cases, I use the way for osgi-javaee application. However , while deploying some *big * osgi bundles(eg. vaadin, ...), deployment time will be very slow, and I have created an issue and wish team will improve it. So, if being the case, please use autodeploy way. I do not suggest using "asadmin osgi install..." except in some special cases(eg. glassfish issue's debugging...), and after all, I think that "asadmin osgi ..." is more oriented into osgi developers.