Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将外部Java库添加到Adobe/Day CRX(2.2)以用于JSP文件_Jsp_Jar_Adobe_Crx - Fatal编程技术网

将外部Java库添加到Adobe/Day CRX(2.2)以用于JSP文件

将外部Java库添加到Adobe/Day CRX(2.2)以用于JSP文件,jsp,jar,adobe,crx,Jsp,Jar,Adobe,Crx,我的公司正在考虑使用AdobeCQ5作为一个新的内容管理系统,我的任务是弄清楚如何使用它做某些事情 我们想做的一件事是在JSP页面的Scriptlet中使用我们为旧web应用程序创建的一些JAR,可能用于调用服务或其他东西 我研究过如何使用OSGi捆绑包,但我认为这不是我们想要做的。 现在,我很难弄清楚在JSP文件中使用外部库的位置 我创建了一个只有泛型类的JAR package org.company.test; import java.lang.String; public class

我的公司正在考虑使用AdobeCQ5作为一个新的内容管理系统,我的任务是弄清楚如何使用它做某些事情

我们想做的一件事是在JSP页面的Scriptlet中使用我们为旧web应用程序创建的一些JAR,可能用于调用服务或其他东西

我研究过如何使用OSGi捆绑包,但我认为这不是我们想要做的。 现在,我很难弄清楚在JSP文件中使用外部库的位置

我创建了一个只有泛型类的JAR

package org.company.test;

import java.lang.String;

public class TestService{
    private String myString;
    public TestService(String input){myString = input;}
    public String getMyString(){return myString;}
}
那是罐子里唯一的东西

我试着把它放到/crx quickstart/server/lib/common

那个文件夹的自述文件上写着

“将库放在此文件夹中,该文件夹应在所有web应用程序和服务器之间共享。”

但是当我尝试访问JSP文件时,它有一些问题。这是完整的JSP文件:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ TR/html4/loose.dtd">
<%%>
<%@page session="false"%>
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%>
<sling:defineObjects/>

<%@ page import="javax.jcr.Repository, javax.jcr.Session, javax.jcr.SimpleCredentials, javax.jcr.Node, javax.jcr.NodeIterator,
                 java.net.URLEncoder, java.util.List, java.util.Iterator, javax.jcr.Value, javax.jcr.RepositoryException,org.company.test.TestService;"%>
<html>
    <head> 
        <style type="text/css"><jsp:include page="/content/myBlog/style.css"/></style>
        <!--<link rel="stylesheet" href="/content/myBlog/style.css" type="text/css">-->
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <% 
            TestService jServ = new TestService("TigerBlood");
            String returnValue = "Failed";
            if(jServ!=null){
                returnValue = jServ.getMyString();
            }            
        %>
        <title><%= returnValue %></title> 
    </head> 
    <body> 
        <a href="/content/myBlog.html" class="imgcontainer"><img src="/apps/myBlog/myBlog.png" width="80px" height="60px" border="0" alt="myBlog" /></a>
        <h1><%= returnValue %></h1>
        <div class="body">
            <br>
            <a href="/apps/myBlog/comment.html">Comment</a>
        </div>
    </body> 
</html>


当我在浏览器中导航到它时,会出现以下错误:

Unable to compile class for JSP: An error occurred at line: 16 in the generated java file Only a type can be imported. org.company.test.TestService resolves to a package 

An error occurred at line: 17 in the jsp file: /apps/myBlog/test.jsp TestService cannot be resolved to a type  
14: <!--<link rel="stylesheet" href="/content/myBlog/style.css" type="text/css">-->  
15: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
16: <%  
17: TestService jServ = new TestService("TigerBlood");  
18: String returnValue = "Failed";  
19: if(jServ!=null){  20: returnValue = jServ.getMyString(); 

An error occurred at line: 17 in the jsp file: /apps/myBlog/test.jsp TestService cannot be resolved to a type  
14: <!--<link rel="stylesheet" href="/content/myBlog/style.css" type="text/css">-->  
15: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
16: <%  
17: TestService jServ = new TestService("TigerBlood");  
18: String returnValue = "Failed";  
19: if(jServ!=null){  
20: returnValue = jServ.getMyString();
无法为JSP编译类:在生成的java文件的第16行发生错误,只能导入类型。org.company.test.TestService解析为一个包
jsp文件:/apps/myBlog/test.jsp TestService的第17行出现错误,无法解析为类型
14:   
15:   
16:   
15:   

16:我找到了答案,您必须将外部库打包为OSGi包

我们可以找到这个过程


很难找到这个答案,尽管这比添加一个罐子要花更多的时间,但它还是有效的

我们使用“Maven bundle plugin”与Maven一起构建cq bundle。您可以使用它根据正确的导出说明创建自己的包

        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>


        <configuration>
            <instructions>
                <Export-Package>
                    org.company.test.*,
                    com.google.gson.*
                </Export-Package>
org.apache.felix
maven捆绑插件
org.company.test.*,
com.google.gson*
在“ExportPackage”标记中,您应该包括希望在jsp中使用的所有包

此外,若您在bundle中使用任何外部jar,那个么您应该在相应的maven pom中指出依赖项

e、 g.对于gson:

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>

com.google.code.gson
格森