English 中文(简体)
What is Facet in JavaEE?
原标题:

I wonder not only what is Facet but also what is Facet in physical level (as I understand it s not a separate jar, but what?)?

I also wonder how can it affect my application after deploying. I ll explain on real example:

I had 2 facets (which were created by IDE): Spring Facet and Web Facet (for jsf). I deployed it to Tomcat and my application worked fine.

Then I added (by means of IDE) one more facet - JPA Facet. I redeployed application and.. it still worked fine :)

So, I m just curious what is that and why do we need it?

最佳回答

This is not Java EE related. This is IDE related. The term is at its own not programming related.

From http://www.thefreedictionary.com/facet

fac·et (fst) n.

  1. One of the flat polished surfaces cut on a gemstone or occurring naturally on a crystal.
  2. Anatomy A small, smooth, flat surface, as on a bone or tooth.
  3. Biology One of the lenslike visual units of a compound eye, as of an insect.
  4. One of numerous aspects, as of a subject. See Synonyms at phase.

It s 4.

In this specific case it s just an aspect which is to be used in the project, so that the IDE can intercept on it with regard to generators, wizards, auto-include libraries and so on. If you add for example the JPA facet, then you will get more options to do the IDE-magic with JPA.

问题回答

As BalusC said, this is not Java EE related but IDE related. This allows to add "characteristics" to a project in a flexible way.

From the IntelliJ IDEA Q&A for Eclipse Users (because you mentioned IDEA):

Q: Facets — what they are for?

A: To streamline the project configuration.

Facets encapsulate the support for a variety of frameworks, technologies and languages. For example, to enable Spring in your project, you only have to add the corresponding facet. All libraries are downloaded and configured, you get the full range of coding assistance, refactorings, etc. Moreover, the code model is also recognized, so you are completely free from worrying about any configuration issues.

In most cases, you can add more than one facet of the same type to your project. For example, you can have multiple Web facets for deploying the application to different servers, or several EJB facets, each for its own EJB version. (See also Project Configuration.)

And yes, Eclipse uses "Facets" too:

alt text

AFAIK, NetBeans doesn t (see Q: How do I configure a web framework for my project?).

As explained in Eclipse & Intellij documentation, Facets define characteristics and requirements (certain configuration, specific for a particular framework/technology).

When you add a facet to a project, that project is configured to perform a certain task, fulfill certain requirements, or have certain characteristics.

In Brief You Have to Follow Some structure to Implement some framework/technology. IDEs have options to implement it for you to make your life easier.

To elaborate it in details I am giving some thorough details directly from Eclipse Documentations. This is Eclipse specific.

While creating a project you will get the option to implement facet for your project. For example, the EAR facet sets up a project to function as an enterprise application by adding a deployment descriptor and setting up the project s classpath.

To add another facet to a project that already exists, complete the following steps:

  1. In the Project Explorer view of the Java™ EE perspective, right-click the project and then select Properties.
  2. Select the Project Facets page in the in the Properties window. This page lists the facets in the project and their versions.
  3. Click Modify Project and select the check boxes next to the facets you want the project to have.

Note: Only the facets that are valid for the project are listed

Some facets may not work together. Thus, you can also choose a preset combination of facets from the Presets list.

  1. Choose a version number for the facet by clicking the current version number and selecting the version number you want from the drop-down list.
  2. Optional: To remove a facet, clear its check box. Not all facets can be removed.
  3. Optional: If you want to limit the project so it will be compatible with one or more runtimes, click on the Runtimes tab and select the runtimes that you want the project to be compatible with. For more information on runtimes, see Specifying target servers for J2EE projects.
  4. Click Finish to exit the Modify Faceted Project dialog and then click OK.

Facets also have version numbers in Eclipse. You can change the version numbers of facets as long as you stay within the requirements for the facets. To change the version of a facet in your project, complete the following steps:

  1. In the Project Explorer view of the Java EE perspective, right-click the project and then select Properties.
  2. Select the Project Facets page in the in the Properties window. This page lists the facets in the project and their versions.
  3. Click Modify Project and click the facet you want to change.
  4. Select the version of the facet from the drop-down box next to the facet s name.
  5. Click Finish to close the Modify Faceted Project window and then click OK.

You can do more things with the facets. I have given the examples for your better understanding. For details, please go through the documentation of your favorite IDE.

Facets is a web application framework that leverages a simple MVC architecture for the server side and a feature-packed Javascript component model for the client. The two pieces are designed to be seemlessly integrated for very dynamic AJAX-style apps





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签