2

I have the following problem regarding multiple versions of jQuery.

I have one instance of jQuery shipped from PrimeFaces JAR (everything works good), then I use a component from another project that injects another instance of jQuery and everything breaks.

My question is: is there a way I can ignore the inclusion of the second jQuery?.

I must add the following: the component which includes the second jQuery works just fine with the first instance of jQuery.

Tiny
  • 27,221
  • 105
  • 339
  • 599
user2271933
  • 491
  • 2
  • 10
  • 25

1 Answers1

4

Easiest way is to put an empty file in the WAR, matching the resource identifier.

Unfortunately you didn't tell which component library exactly it is, so I can't tell you the exact resource location, so here's a generic example based on a library name of library and a resource name of script/jquery.js.

WebContent
 |-- resources
 |    `-- library
 |         `-- script
 |              `-- jquery.js    <-- Empty file!
 :

Resources in WAR have higher classloading precedence than those in JAR, so the empty file would be loaded instead.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Wow... Beauty through simplicity. I was thinking waaaay more complex wih a [custom head renderer](http://kofler.nonblocking.at/2012/10/remove-duplicate-javscript-resources-of-jsf-portlets-in-liferay/) – Kukeltje Mar 11 '15 at 07:33
  • That's just .. amazing. Thank you very much! – user2271933 Mar 11 '15 at 07:40
  • @BalusC, i just tried this solution and on page-load the empty jquery.js is not found. can you guide me a little more please? In the war file I have the structure you recomended: WebContent/resources/jquery/1_9_1/jquery.js – user2271933 Mar 11 '15 at 08:36
  • Apparently you didn't get resource identifier right. What's the original URL of that jQuery library you'd like to suppress? You can extract the right resource identifier from that. – BalusC Mar 11 '15 at 08:39
  • @BalusC I am not sure whats the original URL, I can only know that it's added like this : @ResourceDependency(library = "jquery", name ="1_9_1/jquery.js"), – user2271933 Mar 11 '15 at 08:44
  • The `1_9_1` folder is strange as it matches the resource versioning pattern which should actually not be explicitly specified in library/name. What component library is that? In any case, knowing the exact URL is still helpful in order to determine the right resource identifier. Just look in generated HTML output and grab the ` – BalusC Mar 11 '15 at 08:48
  • This is unfortunately not going to work by overriding the resource from WAR side on. The `1_9_1` folder name pattern is reserved to resource versioning. That's simply a really bad component library you have there. Tell its author to carefully read http://stackoverflow.com/questions/11988415/what-is-the-jsf-resource-library-for-and-how-should-it-be-used (and all of the links therein) and fix the library accordingly. – BalusC Mar 11 '15 at 09:06