maven企业项目使用JSF

maven企业项目使用JSF

本文介绍了交替式根玻璃鱼3.1.2 maven企业项目使用JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找出alternatedocroot。我已经看过stackoverflow的其他问题,并在oracle docs的glassfish(但他们是清楚的泥我的)。



我有一个maven项目,包括web,ejb,ear和聚合器/父模块。在web模块/项目中,我添加了一个带有以下条目的glassfish-web.xml文件:

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE glassfish-web-app PUBLIC - // GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0 // ENhttp://glassfish.org/dtds/glassfish-web-app_3_0 -1.dtd>
< glassfish-web-app error-url =>
< class-loader delegate =true/>
< property name =alternatedocroot_1value =from = / images / * dir = / images/>
< jsp-config>
< property name =keepgeneratedvalue =true>
< description>保留生成的servlet类的java代码的副本。< / description>
< / property>
< / jsp-config>
< / glassfish-web-app>

我已经在Linux系统的根目录下创建了一个图像目录一旦我排序这个问题),并在其中放一个picture.png文件。我做了一个chmod -R 777 / image,所以权限不应该是一个问题。



welcome.xhtml是这样:

 <?xml version ='1.0'encoding ='UTF-8'?> 
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml
xmlns:h =http://java.sun.com/jsf/html>
< h:head>
< h:body>
Hello World
< h:graphicImage url =/ MyProject-web / images / picture.png
height =200
width =960/&
< / h:body>
< / html>

我在运行项目时看到的所有内容都是

Hello World



这是浏览器中运行时的网址:

  http:// localhost:8080 / MyProject-web / 

属性/目录设置和图像url在xhtml文件?

解决方案

所以这里是如何工作在我找到一些我可以理解的东西之前,给我一点时间。



让我们从磁盘上有一些资源或静态内容文件的地方开始。

  / opt / project / resources / images / 
/ opt / project / resources / css /



您想要包含或引用的静态文件如下:

  /opt/project/resources/images/picture.png 
/opt/project/resources/css/screen.css

在glassfish-web.xml中,您将放置(对于两个文档)

 < property name =alternatedocroot_1value =from = / images / * dir = / opt / project / resources/> 
< property name =alternatedocroot_2value =from = / css / * dir = / opt / project / resources/>

在您的xhtml文件中显示图像并链接到外部css文件: p>

 < h:graphicImage url =images / picture.png/> 
< link href =css / screen.css =stylesheettype =text / cssmedia =screen,projection/&

您可以添加其他目录下的图像目录,所以你有类似:

  /opt/project/resources/images/otherimages/anotherpicture.png 

,正如您期望的那样使用它:

  ; h:graphicImage url =images / otherimages / anotherpicture.png/> 

但是,如果你尝试添加一个符号链接到其他图像的位置,不工作。即以下内容不会工作(您将无法访问otherimages符号链接目录中的图片)

  ... / resources / images $ ln -s / somedirectorytree / otherimages / otherimages 

坏。如果有人知道这是真的可能(即如果我错了)我很想知道。或者如果有其他的技巧,而不是求助于硬(编码...为了更好的单词)配置。






编辑



作为一个附注,我想我会添加另一个有用的tidbit与此相关。如果你想确保你在url中获得了你的文件的完整(上下文)路径,你可以添加到前面:

 < link href =$ {facesContext.externalContext.requestContextPath} / 

使用上面的示例:

 < link href =$ {facesContext.externalContext.requestContextPath} /css/screen.css =stylesheet type =text / cssmedia =screen,projection/> 

您总是在您的服务器上查找正确的路径。


I can't seem to figure out alternatedocroot. I have looked at other questions on stackoverflow, and at the oracle docs for glassfish (but they are as clear as mud to me).

I have a maven project with web, ejb, ear, and an aggregator/parent module. In the web module/project I have added a glassfish-web.xml file with the following entry:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <class-loader delegate="true"/>
  <property name="alternatedocroot_1" value="from=/images/* dir=/images " />
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>

I have created an images directory on the root of the Linux box (I'll put it somewhere else once I sort this problem out) and put a "picture.png" file in it. I did a chmod -R 777 /image so permissions should not be an issue.

The welcome.xhtml is this:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
  <h:head>
  </h:head>
  <h:body>
    Hello World
    <h:graphicImage url="/MyProject-web/images/picture.png"
             height="200"
             width="960" />
  </h:body>
</html>

All I see when I run the project is the
"Hello World"

This is the URL in the browser when run:

http://localhost:8080/MyProject-web/

Can someone help me with the property / directory setup / and image url in the xhtml file?

解决方案

So here's how it works (finally). Took me a while before I found something that I could understand. So I'll try to lay it out like nothing else did.

Let's start with where you have some resource or static content files on disk.

/opt/project/resources/images/
/opt/project/resources/css/

And you have static files you want to include or reference like this:

/opt/project/resources/images/picture.png
/opt/project/resources/css/screen.css

In the glassfish-web.xml you would put (for two docroots)

<property name="alternatedocroot_1" value="from=/images/* dir=/opt/project/resources" />
<property name="alternatedocroot_2" value="from=/css/* dir=/opt/project/resources" />

In your xhtml file to display an image and link to an external css file you do this:

<h:graphicImage url="images/picture.png" />
<link href="css/screen.css" rel="stylesheet" type="text/css" media="screen, projection" />

You can add other directories under say, the images directory so you have something like:

/opt/project/resources/images/otherimages/anotherpicture.png

and just as you would expect you would use it like:

<h:graphicImage url="images/otherimages/anotherpicture.png" />

However it appears that if you try to add a symbolic link to where the other images are, it won't work. i.e. the following won't work (you won't be able to access the images in the "otherimages" symbolically linked directory)

.../resources/images$ ln -s /somedirectorytree/otherimages/ otherimages

Which is too bad. If someone knows if this is really possible (i.e. if I'm mistaken) I'd love to know. Or if there are other tricks rather than resort to hard (coded... for want of a better word) configuration. It would be nice to just be able to add links to other file systems.


Edit

As a side note, I thought I would add another helpful tidbit that relates to this. If you want to make sure you get the complete (context) path to your file in the url you can add this in front:

<link href="${facesContext.externalContext.requestContextPath}/

Using an example from above:

<link href="${facesContext.externalContext.requestContextPath}/css/screen.css" rel="stylesheet" type="text/css" media="screen, projection" />

This will ensure you are always looking in the correct path on your server.

这篇关于交替式根玻璃鱼3.1.2 maven企业项目使用JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 18:41