How to specify the packaging method for a new library of a web module?

If I add a new library to a web module with a plugin, what is the correct way of specifying the packaging method for it? At the moment, IDEA defaults to "Do nothing" (or something similar) and I would like to somehow choose "Copy file".

If I add the library manually, IDEA does select the "Copy file" for it automatically.

There was an earlier thread about the same topic at http://www.intellij.net/forums/thread.jsp?forum=23&thread=129380 but the solution looks a bit hackish and does not seem to work with the latest version of IDEA anyway.

All help would be appreciated.

5 comments

It seems none of the regular users of this forum know the answer to this one. How about you, the guys at JetBrains? I would like to know the answer and if this is not the place to ask about the unclear things about the Open API, then what is?

When I have a problem with the Open API, the first thing I do is search this forum. And usually I immediately find the answer. That's why it's so sad to find questions that has not been answered to - even if the answer would have been "It's not supported at the moment".

0

I would also like to know. I tried something similar to this with the 6.0.1 OpenAPI:

if (module.getModuleType().isJ2EE()) {

JavaeeModuleProperties props = JavaeeModuleProperties.getInstance(module);

for (LibraryLink lib : props.getContainingLibraries()) {

if (!lib.getPackagingMethod().equals(J2EEPackagingMethod.DO_NOT_PACKAGE)) {
lib.setPackagingMethod(J2EEPackagingMethod.DO_NOT_PACKAGE);
}
}
}

The problem is that the getContainingLibraries() call always returns a zero-length array. There are libraries in the module, so why can;t I access them?

Thanks in advance,

- Bryan

0
Avatar
Nikolay Chashnikov

Hello Bryan,

getContainingLibraries() doesn't include libraries with the packaging method
set to "Do not package". So this method will return zero-length arrray only
if none of module's libraries is marked to package.

If you want to set packaging method for all libraries to "Do not package"
you should write:

TransactionalEditable editable = (TransactionalEditable) JavaeeModuleProperties.getInstance();
editable.startEdit(null);
ModuleContainer modifiable = editable.getModifiableModel();
for (LibraryLink link : modifiable.getContainingLibraries()) {
link.setPackagingMethod(J2EEPackagingMethod.DO_NOT_PACKAGE);
}
editable.commit(null);

I would also like to know. I tried something similar to this with the
6.0.1 OpenAPI:

if (module.getModuleType().isJ2EE()) {

JavaeeModuleProperties props =
JavaeeModuleProperties.getInstance(module);

for (LibraryLink lib : props.getContainingLibraries()) {

if
(!lib.getPackagingMethod().equals(J2EEPackagingMethod.DO_NOT_PACKAGE))
{

lib.setPackagingMethod(J2EEPackagingMethod.DO_NOT_PACKAGE);
}
}
}
The problem is that the getContainingLibraries() call always returns a
zero-length array. There are libraries in the module, so why can;t I
access them?

Thanks in advance,

- Bryan



0

Nikolay,

Thanks for your reply. This gets me a little closer, but I am still only getting the libraries that are set to be packaged. If I debug the application, I can see that the container variable 'modifiable' is of type 'WebModulePropertiesImpl' and contains a variable of type 'ModuleContainerImpl'. That module container has a set in it that corresponds to what I am seeing in the GUI, but I cannot figure out how to get access to it. My goal is to manipulate this set (since it does not seem to correspond to the library listing of the module itself) and make it consistent with the module.

Thanks in advance,

- Bryan

0
Avatar
Nikolay Chashnikov

Hello Bryan,

Unfortunately you cannot directly access non-packaged libraries using Open
API.
In order to mark some library for packaging you should write:

TransactionalEditable editable = (TransactionalEditable) JavaeeModuleProperties.getInstance();
editable.startEdit(null);
ModuleContainer modifiable = editable.getModifiableModel();

LibraryLink link = MakeUtil.getInstance().createLibraryLink(library, module);
modifiable.addElement(link);

editable.commit(null);

Nikolay,

Thanks for your reply. This gets me a little closer, but I am still
only getting the libraries that are set to be packaged. If I debug the
application, I can see that the container variable 'modifiable' is of
type 'WebModulePropertiesImpl' and contains a variable of type
'ModuleContainerImpl'. That module container has a set in it that
corresponds to what I am seeing in the GUI, but I cannot figure out
how to get access to it. My goal is to manipulate this set (since it
does not seem to correspond to the library listing of the module
itself) and make it consistent with the module.

Thanks in advance,

- Bryan



0

Please sign in to leave a comment.