Using JavaEE and Web facets - Packaging is not working

I have a module "M1" with some classes in src directory. Then I have two web apps defined under M1 as Web facets "W1" and "W2". Then I define JavaEE Application facet "EE" under M1 which contains W1 and W2. Each web app uses M1 classes.

The module and library packaging defined in project settings is following:

W1:
- JAR module M1, link via manifest and copy to /
- create W1.war file

W2:
- JAR module M1, link via manifest and copy to /
- create W2.war file

EE:
- package W1.war
- package W2.war
- M1.jar is not visible here!
- create ear file EE.ear

Result after Make:
The EE.ear is created with two war files in it. In war files is manifest file, but Class-Path attribute is empty. No M1.jar is created anywhere.

How it should be:
The M1.jar should be created in EE.ear side by side with both war files. In every war in the manifest file the M1.jar should be included in Class-Path attribute.
For details see Mechanism 2: Bundled Optional packages in http://java.sun.com/j2ee/verified/packaging.html

PS: Duplicating M1 by packaging it into W1 and W2 as WEB-INF/classes or WEB-INF/lib/M1.jar is working ok but that's not what I want.

PS2: Another problem is when I check "Create exploded directory" instead of ear file. In this case I get "Error copying .../M1.jar into .../EE. Destination is a directory." error message when I Make the project.

This is very intriquing because it obviously wants to create jar file but fails on this bogus error. When I switch to "Create ear file" I have no error but the jar is not created anyway.

Can somebody explain this strange behavior?
How can I do "Mechanism 2" packaging in IDEA?

Thanks

8 comments

Hello Steve,

I've created a dummy project following your description (attached harb-07-j2ee.zip). It seems to be working: after compilation there is out/ee1.ear with required jar inside. The described bug can occur with some conditions specific for your project or environment.

How can I do "Mechanism 2" packaging in IDEA?
Thanks

>
Alexander.

Attachment not added (general error): "harb-07-j2ee.zip"

0

Thanks for the reply. Good to hear that it works for you as I would expect. My current test project was also from scratch but contains some more web apps. I will try it again with a new project completely from scratch and then compare the differences. At some point I will find the problem :)

0

And PS the zip attachment is missing.

0

So I have created dummy project from scratch. It is not working for me. Maybe I'm doing something stupid. I will try to attach the zip with the project.



Attachment(s):
WebProject1.zip
0

The problem is caused by empty value in "Path relative to deployment
root" field for module WebProject in settings of web facets. There was
bug (http://jetbrains.net/jira/browse/IDEADEV-20408, fixed in 7.0.2)
which prevents IDEA from setting correct default value for this field
and reporting error when field is empty.

So I have created dummy project from scratch. It is not working for me. Maybe I'm doing something stupid. I will try to attach the zip with the project.



--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Hello Steve,

Beside the fix described by Nikolay one more thing is necessary. Your dummy
project was not compilable for me too, until I provide jar name in web facet
settings / "Modules and Libraries to Package" table / "Path relative to deployment
root" column. Originally it was "/" in both facets, I have changed it to
"/module.jar" for both, and got it.

Strange, that the name was not provided by IDEA, normally it is performed.

So I have created dummy project from scratch. It is not working for
me. Maybe I'm doing something stupid. I will try to attach the zip
with the project.

Alexander.


0

Yes, the path was "/" which is the value set by IDEA when you change the Packaging method. I did not realize I have to change it manually to "/module.jar".

When I think about it now I think it is quite confusing. The path is changed by IDEA and when I changed packaging to "JAR module, link via manifest and copy to" I automatically expected that the "/" path means where the jar would be copied to :)

Anyways I have just downloaded version 7.0.2. With all the new info from you guys I will test it again asap.

0

So I have tested it and it works now!

In version 7.0.2 the path generated by IDEA is directly "/module.jar" instead of "/", which is great. The jar is generated and included in manifests. The generating into exploded directory throws no errors and works ok as well as generating into ear archive.

Thanks again for all the help guys.

0

Please sign in to leave a comment.