Glassfish 4.1.1和离线JSP编译器(JSP和OSGI) [英] Glassfish 4.1.1 and offline JSP compiler (JSP and OSGI)

查看:132
本文介绍了Glassfish 4.1.1和离线JSP编译器(JSP和OSGI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,jsp无法使用当前osgi web归档包之外的类。这是GF中的一个错误。用于解决此错误的glassfish开发人员 https://java.net/jira/browse/GLASSFISH- 11208 提供使用脱机jsp编译器(换句话说,不是在部署期间编译jsp文件,而是在构建存档期间)。好的,我在构建wab时使用jspc-maven-plugin编译我的jsp。

 < plugin> 
< groupId> org.codehaus.mojo< / groupId>
< artifactId> jspc-maven-plugin< / artifactId>
< version> 1.4.6< / version>
<执行次数>
<执行>
<目标>
< goal>编译< / goal>
< /目标>
< id>编译< / id>
< /执行>
< /执行次数>
<配置>
< / configuration>
< / plugin>

jsp已经编译完成,我可以在构建的web档案中看到他们的.classes。



现在的问题 - 我该如何让glassfish使用我编译的jsp,而不是自己编译它?因为我发现GF忽略编译的.class文件并生成.javas文件并编译它们本身。



编辑1 我现在所做的是:
1)我添加到glassfish-web.xml中

 < jsp-config> 
< property name =usePrecompiledvalue =true/>
<! - 看到它不会生成.javas - >
< property name =keepgeneratedvalue =true/>
< / jsp-config>



<2>当我构建我的wab存档时,我在 WEB中有jsp类-INF / classes / jsp /...但是,我发现jsp文件没有找到。当我手动将jsp类移动到 WEB-INF / classes / org / apache / jsp ... 容器现在看到这些类,但是我得到了

  StandardWrapperValve [默认值]:servlet默认的Servlet.service()抛出异常
java.lang.ClassLoader.defineClass1(本地方法)
java.lang.NoClassDefFoundError:org / apache / jsp / ...(错误名称:jsp / ...) .ClassLoader.defineClass(ClassLoader.java:760)
at org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
at org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.findClass(BundleWiringImpl.java:2154)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
at org.apache.felix.framework.BundleWiringImpl.access $ 400(BundleWiringImpl.java:79)
在org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.loadClass(BundleWir
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1925)
在org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:978)
在org.glassfish.osgijavaeebase.BundleClassLoader.loadClass(BundleClassLoader.java:79)
在org.glassfish .osgiweb.OSGiWebDeploymentContext $ WABClassLoader.loadClass(OSGiWebDeploymentContext.java:169)
at org.glassfish.osgiweb.OSGiWebDeploymentContext $ WABClassLoader.loadClass(OSGiWebDeploymentContext.java:154)
at org.apache.jasper.JspCompilationContext .load(JspCompilationContext.java:654)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:202)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper .java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspS ervlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)

所以知道这是正确的路径 - org / apache / jsp。问题是如何让maven插件输出到这个方向?

编辑2
所以我找到了这个maven的设置插件 -

 < plugin> 
< groupId> org.codehaus.mojo< / groupId>
< artifactId> jspc-maven-plugin< / artifactId>
< version> 1.4.6< / version>
<执行次数>
<执行>
<目标>
< goal>编译< / goal>
< /目标>
< id>编译< / id>
<配置>
< packageName> org.apache.jsp< / packageName>
< / configuration>
< /执行>
< /执行次数>
<配置>
< / configuration>
< / plugin>

然而,这是最后一点,但不是结果。因为我没有例外,所以返回的http请求是空的(浏览器中的空白页)。似乎我应该使用另一个maven插件,但哪一个?

解决方案

因此,对于我在编辑中所做的所有步骤修改web.xml文件是必要的,因为插件会添加从jsp页面生成的servlet的映射。所以,最终的设置是:

 < plugin> 
< groupId> org.codehaus.mojo< / groupId>
< artifactId> jspc-maven-plugin< / artifactId>
< version> 1.4.6< / version>
<执行次数>
<执行>
<目标>
< goal>编译< / goal>
< /目标>
< id>编译< / id>
<配置>
<! - 将编译后的jsp类放入的包 - >
< packageName> org.apache.jsp< / packageName>
<! - 插件将servlets添加到此web.xml文件 - >
< outputWebXml> $ {project.build.directory} /web.xml< /outputWebXml>
<详细>真< /详细>
< target> 8< / target>
< source> 8< / source>
< / configuration>
< /执行>
< /执行次数>
<配置>
< / configuration>
< / plugin>

编辑
最后我发现jasper的版本在GlassFish 4.1中是未知的,甚至是可以修改的 - >我得到了这样的方法没有找到的异常等等。所以我以下面的结尾 - 我将这个插件的源代码加载并使其使用了glassfish中的碧玉版本。我没有在插件的源代码中做任何修改,只在pom.xml中做过修改。所以最后的pom变成了:

 < project xmlns =http://maven.apache.org/POM/4.0。 0xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache .ORG /行家-v4_0_0.xsd> 
<! - < parent>
< artifactId> mojo< / artifactId>
< groupId> org.codehaus.mojo< / groupId>
< version> 11< / version>
< / parent> - >
< modelVersion> 4.0.0< / modelVersion>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> jspc-maven-plugin< / artifactId>
< version> 1.4.6< / version>
< packaging> maven-plugin< / packaging>
< name> Maven Jspc插件< /名称>
<开发者>
< developer>
< name> Jeff Genender< / name>
< email> jgenender@apache.org< / email>
< organization> Savoir Technologies< / organization>
< organizationUrl> http://www.savoirtech.com< / organizationUrl>
< timezone> -7< / timezone>
< / developer>
< / developers>
< contributors>
< contributor>
<名称> Grzegorz Slowikowski< / name>
< email> gs@tiger.com.pl< / email>
< organization> Scott Tiger S.A.< / organization>
< organizationUrl> http://www.tiger.com.pl< / organizationUrl>
< timezone> + 1< / timezone>
< / contributor>
< contributor>
<名称> Pawel Pastula< / name>
< email> pablo@tiger.com.pl< / email>
< organization> Scott Tiger S.A.< / organization>
< organizationUrl> http://www.tiger.com.pl< / organizationUrl>
< timezone> + 1< / timezone>
< / contributor>
< / contributors>

<依赖关系>
<! - 来自glassfish 4.1.1模块文件夹,我们需要:
javax.servlet.jsp.jar
javax.servlet-api.jar
javax.servlet.jsp -api.jar
javax.el.jar
javax.servlet.jsp.jstl-api.jar
javax.servlet.jsp.jstl.jar
此jar的什么版本你可以在玻璃鱼的父母pom中找到
http://repo.maven.apache.org/maven2/org/glassfish/main/glassfish-parent/4.1.1/glassfish-parent-4.1.1.pom
和清单文件
- >
< dependency>
< groupId> javax.servlet< / groupId>
< artifactId> javax.servlet-api< / artifactId>
< version> 3.1.0< / version>
< /依赖关系>
< dependency>
< groupId> javax.servlet.jsp< / groupId>
< artifactId> javax.servlet.jsp-api< / artifactId>
< version> 2.3.2-b01< / version>
< /依赖关系>
< dependency>
< groupId> org.glassfish.web< / groupId>
< artifactId> javax.servlet.jsp< / artifactId>
< version> 2.3.3-b02< / version>
< /依赖关系>
< dependency>
< groupId> org.glassfish< / groupId>
< artifactId> javax.el< / artifactId>
< version> 3.0.0< / version>
< /依赖关系>
< dependency>
< groupId> javax.servlet.jsp.jstl< / groupId>
< artifactId> javax.servlet.jsp.jstl-api< / artifactId>
< version> 1.2.1< / version>
< /依赖关系>
< dependency>
< groupId> org.glassfish.web< / groupId>
< artifactId> javax.servlet.jsp.jstl< / artifactId>
< version> 1.2.4< / version>
< /依赖关系>
<! - 我们需要这种依赖关系,因为它包含核心标记库的文件 - >
< dependency>
< groupId> org.eclipse.jetty.orbit< / groupId>
< artifactId> org.apache.jasper.glassfish< / artifactId>
< version> 2.2.2.v201112011158< / version>
< /依赖关系>
< dependency>
< groupId> ant< / groupId>
< artifactId> ant< / artifactId>
< version> 1.6.5< / version>
< /依赖关系>
< dependency>
< groupId> org.apache.maven< / groupId>
< artifactId> maven-plugin-api< / artifactId>
< version> 2.0< / version>
< /依赖关系>
< dependency>
< groupId> org.apache.maven< / groupId>
< artifactId> maven-project< / artifactId>
< version> 2.0< / version>
< /依赖关系>
< dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.13< / version>
< scope>运行时< / scope>
< /依赖关系>
< /依赖关系>
< / project>

当你编译你的bundle时,你必须添加下列依赖项:

 < dependency> 
< groupId> org.glassfish.web< / groupId>
< artifactId> javax.servlet.jsp< / artifactId>
< version> 2.3.3-b02< / version>
< /依赖关系>
< dependency>
< groupId> org.glassfish.web< / groupId>
< artifactId> javax.servlet.jsp.jstl< / artifactId>
< version> 1.2.4< / version>
< /依赖关系>

除此之外,您还需要从glassfish导入一些软件包才能正常工作。所以在结果中你可以使用带有glassfish的预编译的jps文件,但是你需要在它之前做一些事情。正如你所见,你将你的代码链接到GF。



最重要的是 - 你可以使用jsp中其他osgi包的类来工作!对于那些在java-ee中使用osgi的人来说,这可能非常重要。在完成所有这些步骤之后,我必须得出结论:尽管开发人员给出了建议,但 GF不支持用于预制JPS文件



我希望至少有一位会理解所有的解决方案,因为在我看来,这是互联网上第一个如何在GF中使用预编译jps页面的描述。顺便说一句,如果你使用osgi,它会抱怨它找不到类导入必要的包。


As everyone knows jsp can't work with classes outside current osgi web archive bundle. This is a bug in GF. The developers of glassfish for workaround of this bug https://java.net/jira/browse/GLASSFISH-11208 offer to use offline jsp compiler (by other words to compile jsp files not during deployment time but during archive building time). Ok, and I used jspc-maven-plugin to compile my jsp during wab building.

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>jspc-maven-plugin</artifactId>
 <version>1.4.6</version>
 <executions>
     <execution>
         <goals>
             <goal>compile</goal>
         </goals>
         <id>compile</id>
     </execution>
 </executions>
 <configuration>
 </configuration>
</plugin>

The jsp are compiled and I see their .classes in built web archive.

Now the problem - how can I make glassfish use my compiled jsp but not to compile it itself? Because I see that GF ignores compiled .classes and generate .javas and compile them itself.

EDIT 1 What I make up to now: 1) I added to glassfish-web.xml

  <jsp-config>
        <property name="usePrecompiled" value="true"/>
        <!-- to see it doesn't generate .javas -->
        <property name="keepgenerated" value="true" />
    </jsp-config>

2)And when I build my wab archive I have jsp classes in WEB-INF/classes/jsp/... However, I get exception that jsp file not found. When I manually move jsp classes to WEB-INF/classes/org/apache/jsp... I see that container now sees these classes but I get

  StandardWrapperValve[default]: Servlet.service() for servlet default threw exception
java.lang.NoClassDefFoundError: org/apache/jsp/... (wrong name: jsp/...)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1925)
    at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:978)
    at org.glassfish.osgijavaeebase.BundleClassLoader.loadClass(BundleClassLoader.java:79)
    at org.glassfish.osgiweb.OSGiWebDeploymentContext$WABClassLoader.loadClass(OSGiWebDeploymentContext.java:169)
    at org.glassfish.osgiweb.OSGiWebDeploymentContext$WABClassLoader.loadClass(OSGiWebDeploymentContext.java:154)
    at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:654)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:202)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)

So know this is the right path - org/apache/jsp. The question is how to make maven plugin to output to this direction?

EDIT 2 So I found the settings of this maven plugin -

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>jspc-maven-plugin</artifactId>
 <version>1.4.6</version>
 <executions>
     <execution>
         <goals>
             <goal>compile</goal>
         </goals>
         <id>compile</id>
         <configuration>
             <packageName>org.apache.jsp</packageName>
         </configuration>
     </execution>
 </executions>
 <configuration>
 </configuration>
</plugin>

However, this is the final point but not result. As I get no exception, bute the returned http request is empty (blank page in browser). Seems I should use another maven plugin but which one?

解决方案

So, to all steps which I did and explained in my edit it is necessary to modify web.xml file because plugin will add there mapping for servlets generated from jsp pages. So, the final settings are :

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>jspc-maven-plugin</artifactId>
 <version>1.4.6</version>
 <executions>
     <execution>
         <goals>
             <goal>compile</goal>
         </goals>
         <id>compile</id>
         <configuration>
             <!-- package where the compiled jsp classes will be put -->
             <packageName>org.apache.jsp</packageName>
             <!-- the plugin adds servlets to this web.xml file -->
<outputWebXml>${project.build.directory}/web.xml</outputWebXml>
          <verbose>true</verbose>
         <target>8</target>
         <source>8</source>
         </configuration>
     </execution>
 </executions>
 <configuration>
 </configuration>
</plugin>

EDIT Finally I found out that the version of jasper in GlassFish 4.1 is not known or even can be modified -> I got exceptions that such method not found etc. So I ended with the following - I donwloaded the sources of this plugin and made it use the version of the jasper in glassfish. I did not do any modifications in source code of the plugin, only in pom.xml. So the final pom became:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <!--<parent>
    <artifactId>mojo</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <version>11</version>
  </parent>-->
    <modelVersion>4.0.0</modelVersion>
      <groupId>org.codehaus.mojo</groupId>
    <artifactId>jspc-maven-plugin</artifactId>
    <version>1.4.6</version>
    <packaging>maven-plugin</packaging>
    <name>Maven Jspc plugin</name>
    <developers>
        <developer>
            <name>Jeff Genender</name>
            <email>jgenender@apache.org</email>
            <organization>Savoir Technologies</organization>
            <organizationUrl>http://www.savoirtech.com</organizationUrl>
            <timezone>-7</timezone>
        </developer>
    </developers>
    <contributors>
        <contributor>
            <name>Grzegorz Slowikowski</name>
            <email>gs@tiger.com.pl</email>
            <organization>Scott Tiger S.A.</organization>
            <organizationUrl>http://www.tiger.com.pl</organizationUrl>
            <timezone>+1</timezone>
        </contributor>
        <contributor>
            <name>Pawel Pastula</name>
            <email>pablo@tiger.com.pl</email>
            <organization>Scott Tiger S.A.</organization>
            <organizationUrl>http://www.tiger.com.pl</organizationUrl>
            <timezone>+1</timezone>
        </contributor>
    </contributors>

    <dependencies>
        <!-- from glassfish 4.1.1 modules folder we need:
        javax.servlet.jsp.jar
        javax.servlet-api.jar
        javax.servlet.jsp-api.jar
        javax.el.jar
        javax.servlet.jsp.jstl-api.jar
        javax.servlet.jsp.jstl.jar
        what versions of this jar you can find out in parent pom of glassfish
        http://repo.maven.apache.org/maven2/org/glassfish/main/glassfish-parent/4.1.1/glassfish-parent-4.1.1.pom
        and in manifest file
        -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.2-b01</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.servlet.jsp</artifactId>
            <version>2.3.3-b02</version>
        </dependency>        
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.el</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.servlet.jsp.jstl</artifactId>
            <version>1.2.4</version>
        </dependency>
        <!-- we need this dependency as it contais tld files for core tag library -->
        <dependency>
            <groupId>org.eclipse.jetty.orbit</groupId>
            <artifactId>org.apache.jasper.glassfish</artifactId>
            <version>2.2.2.v201112011158</version>
        </dependency>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.6.5</version>
        </dependency>        
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-project</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.13</version>
            <scope>runtime</scope>
        </dependency>        
    </dependencies>
</project>

When you will compile you bundle you will have to add the following dependencies:

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp</artifactId>
    <version>2.3.3-b02</version>
</dependency>       
<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp.jstl</artifactId>
    <version>1.2.4</version>
</dependency>

Besides you will need to import some packages from glassfish to make it work. So in result you can use precompiled jps files with glassfish, but you need to make some things before it. And as you see you link your code to GF.

The most important thing - you can work with classes from other osgi bundles in jsp! For those who work with osgi in java-ee this can be very important. After doing all these steps I must conclude that GF IS NOT SUPPORTED TO BE USED WITH PRECOMPILED JPS FILES in spite of suggestions from the developers.

I hope at least one will appreciate all the solution, because it seems to me this is the first description in internet how to use precompiled jps pages with GF. By the way if you use osgi and it complains it can't find classes import the necessary packages.

这篇关于Glassfish 4.1.1和离线JSP编译器(JSP和OSGI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆