users@glassfish.java.net

Re: Embedded GlassFish Plugin with ScatteredArchive?

From: Magnus Kvalheim <magnus_at_kvalheim.dk>
Date: Fri, 9 Sep 2011 12:18:50 +0200

Thoughts embedded glassfish and incremental deployment.

I've checked out some documentation and it seems like it should be possible
to do directory deployment with the embeddable deployer.
What I would like to see of new features in the embedded-maven-plugin is:
* deploy to embedded glassfish without previous packaging of artifacts
* incremental updates of changes

Suggested approach:
1. initially package application as scatteredarchive with maven
dependencies/artifacts added to archive classpath.
2. deploy scattered archive
3. register resources to be watched - for example through new java.nio. ->
target/classes + src/main/webapp
4. whenever files change. find deployed directory and sync changed file(s).

To redeploy - steps 1+2 are repeated.

btw - as mentioned before I've already successfully tested 1+2 by monkey
patching maven-embedded-glassfish-plugin.

Optional approach for step 1:
Manually create the exploded war dir and deploy this instead of the
scatteredarchive.
Would do this to mimic what the wtp plugin does where workspace dependencies
are put in WEB-INF/lib as a folder with .jar name. I'm expecting that
glassfish classloader has the feature to load exploded jars built in.
That way any references to jarfile for example in persistence.xml should
also work.


And - these features are is not just for my personal benefit. I've seen
numerous posts around and even plugins for this(
http://code.google.com/p/manik-hot-deploy/).
I think it could help glassfish in gaining more attention from developers
looking for an effective development process with jee and maven.

So let's unleash the power of development with maven and glassfish! :)

Looking forward to your input

Thanks in advance
Magnus Kvalheim

On Mon, Sep 5, 2011 at 11:17 PM, Magnus Kvalheim <magnus_at_kvalheim.dk> wrote:

> Hi Bhavanishankar - hope it's ok that I keep writing you,
>
> I looked into jetty's maven plugin implementation - and got it working for
> glassfish as well - turned out to be quite simple in the end...
>
> I tested with 2 projects; A and B - where
> * project A have B as a dependency
> * Both projects are open in workspace
> This runs fine as scatteredarchive from maven.
>
> I wasn't aware that it's actually built as a war file before it's deployed
> (dough!) - so my assumption that it would be possible to hot-replace
> resources and classes were totally wrong.
> Is it possible at all? exploded war / directory - with incremental
> updates ?
>
> In any case I think it's a nice and useful addition to have an
> implementation for the scatteredarchive though. (Very little code is needed,
> I can share if it's useful)
>
> Thanks
> Magnus Kvalheim
>
>
> On Mon, Sep 5, 2011 at 10:41 AM, Magnus Kvalheim <magnus_at_kvalheim.dk>wrote:
>
>> Hi again,
>>
>> I've still not been able to move forward with this - redeploy has no
>> effect.
>> What I'm aiming for is to streamline development cycles and env.
>> Previously I've setup eclipse with wtp + oracle tools(glassfish plugin) +
>> m2eclipse wtp plugin. This combination was far from ideal and encountered
>> numerous problems with deploy and debug.
>>
>> A 'pure' maven configured setup seems more appealing - and would not
>> require developers to install x number of additional plugins for setting
>> everything up.
>> According to
>> http://embedded-glassfish.java.net/nonav/plugindocs/3.1/runscatteredarchive-mojo.html says
>> that* no usecase exist for running as scattered archive* - however I
>> think I have a valid one.
>>
>> *Glassfish ScatteredArchive as alternative to jetty:run with workspace
>> resolution (and as alternative to WTP)*
>> The major selling points:
>> * A full build and install to local repository is not needed. Not for the
>> run target - or for any of it's dependent projects in current workspace.
>> * Changes to files(not bytecode); html, js, templates++ are reflected
>> immediately
>> * Frameworks which do it's own classloading and bytecode manipulation
>> don't require redeloy for reflecting 'java'/class changes. (An example is
>> Tapestry 5 which provides JRebel like features for it's managed classes).
>>
>> - For changes to normal classes hitting enter in console is totally fine
>> for redeloy.
>> *
>> *
>> I believe that we have everything we need for implementing the goal.
>> I've checked out sources for
>> https://svn.java.net/svn/glassfish~svn/tags/embedded-maven-plugin-3.1.1
>> Unfortunaley I've never worked with implementation of maven plugins
>> before, so I couldn't complete - but I guess it's a matter of adding
>> dependency artifacts to classpath of scatteredarchive.
>> Maven jetty plugin is probably doing the same so perhaps one can look at
>> this for inspiration.
>>
>> What do you think? Is it feasible to implement this goal so that one can
>> run a project from build target?
>>
>> I would be more than happy to help out with implementation and test.
>>
>> --magnus
>>
>> On Mon, Aug 22, 2011 at 9:31 PM, Magnus Kvalheim <magnus_at_kvalheim.dk>wrote:
>>
>>> Hi _Bhavani, thank you for your quick reply
>>>
>>> On Mon, Aug 22, 2011 at 6:05 PM, Bhavanishankar <
>>> bhavanishankara.sapaliga_at_oracle.com> wrote:
>>>
>>>> Hi Magnus Kvalheim,
>>>>
>>>>
>>>> On 08/22/2011 09:26 PM, Magnus Kvalheim wrote:
>>>>
>>>> Hi Bhavanishankar,
>>>>
>>>> I have successfully deployed a web application which uses maven
>>>> structure.
>>>> This is deployed as scattered archive so I would not need to package
>>>> artifact.
>>>>
>>>> * ScatteredArchive archive = new ScatteredArchive("testapp",
>>>> ScatteredArchive.Type.WAR, new File("src/main/webapp"));*
>>>> * archive.addClassPath(new File("target", "classes"));*
>>>>
>>>> When the server is running I have it setup so that I can hit enter in
>>>> eclipse console for reloading.
>>>> I deploy with commands:
>>>> *deployer.deploy(archive.toURI(), "--force=true",
>>>> "--keepstate=true");*
>>>>
>>>> The problem is that changes to class files are not
>>>> reflected/redeployed.
>>>>
>>>> I believe the deployment goes fine and you are able to access the app.
>>>> But what you are saying is if you change the files under target/classes
>>>> later it is not getting reflected when you access the app again. Is my
>>>> understanding correct?
>>>>
>>>
>>> Yes. The app is working and I can access.
>>> As mentioned I'm running from eclipse - with embedded glassfish using the
>>> eclipse project build path.
>>> When I modify code and save, it will compile to target/classes.
>>> At this point I (re)deploy app with --force, but no changes are
>>> reflected.
>>>
>>> My initial assumption was that the problems was related to eclipse and
>>> glassfish classloaders, but it's just a guess ...
>>> Have you got any suggestion?
>>>
>>> many thanks in advance
>>> Magnus
>>>
>>>
>>>>
>>>> _Bhavani.
>>>>
>>>>
>>>> I'm running this from eclipse and suspect that there could be a
>>>> possible classoading issue when both eclipse and glassfish get in the mix.
>>>> (Classpath is coming from maven and target/classes both resolved by
>>>> eclipse)
>>>>
>>>>
>>>> I think though that it could work better if it would be running as
>>>> a ScatteredArchive from the glassfish plugin - then eclipse build path would
>>>> not interfere...
>>>>
>>>> Do you think it's possible now to make the maven glassfish plugin run
>>>> and deploy a maven project without packaging war artifact
>>>> (ScatteredArchive)?
>>>>
>>>> This would be a huge benefit for us - and I guess anyone that are
>>>> coming from dev cycles with jetty:run
>>>> And I think it would also give the added benefit of resolving workspace
>>>> artifacts - so packaging/install of related projects also can be avoided.
>>>>
>>>> best regards
>>>> Magnus Kvalheim
>>>>
>>>>
>>>> --
>>>> Sun, an Oracle Company
>>>>
>>>>
>>>
>>
>