0

I'm using a javascript library to develop a interface with 3D graphics in a JSF project with Maven and I was wondering if there is a way to add/import this js library into my project without having to move/copy all the js files into the webapp/resources directory. I already tried to do it with the tags and within the tag of the pom.xml file but it didn't work.

The error is produced by this line:

<h:outputScript name="Three.js" />

It says the resource is not found.

Thanks in advance.

EDIT: I'm using JFS 2.1

miguel0afd
  • 305
  • 3
  • 15

1 Answers1

2

Maven is a tool for among others managing java dependencies, and building your application. It is used to produce a java application. As you understand, JavaScript runs on the client side in a web application, while java runs on the server side. But sometimes Maven can import JS resources as an integral part of a java library. PrimeFaces is one example.

As to the resource management within a JSF application, including JS scripts, you've basically got two ways:

  1. Import external scripts with a plain HTML <script> element. This way you don't need to do any imports and just reference an external to JSF script.
  2. Import internal scripts with a <h:outputScript>. This way, resources and in particular your scripts, will be imported from within a web application, most possibly, but not necessarily, from within your resources folder. Otherwise, you can access scripts from maven imported artifacts, like PrimeFaces, that include JS resources as well. In this case you need to specify library attribute of <h:outputScript>.

To my knowledge, no java library ships with Three.js included, so your best bet is to either reference an external script, or import it within your JSF project. But if I'm wrong - just go ahead and incude that library via Maven to be able to reference it in your views.

skuntsel
  • 11,624
  • 11
  • 44
  • 67
  • By the way, I'm using RichFaces. The thing is that I want to import all the js files into my JSF project with the outputScript tag including the library property but I don't know how to do it without copying all of them into the reosurce library. What should I do? Should I write until it reaches the directory where I actual have the js files? You said that I can import scripts and not necessarily from within my source folder and that's my problem, I don't know how to import scripts from a different directory. – miguel0afd May 09 '13 at 09:37
  • Go through excellent [What is the JSF resource library for and how should it be used?](http://stackoverflow.com/questions/11988415/what-is-the-jsf-resource-library-for-and-how-should-it-be-used) and [Maven and JSF webapp structure, where exactly to put JSF resources](http://stackoverflow.com/questions/13540907/maven-and-jsf-webapp-structure-where-exactly-to-put-jsf-resources) answers before proceeding any further. – skuntsel May 09 '13 at 09:47
  • Well, after a few hours reading those links and other documentation, I couldn't find a real solution so I'll finally copy all the js files into the webapp/resources directory but thanks anyway. – miguel0afd May 09 '13 at 11:24
  • Basically it's the most straight way and IMO the only proper one. – skuntsel May 09 '13 at 11:29