2013-09-25 111 views
2

我要創建我自己的插件來解析XML和做其他的東西使用外部罐。我已經建立了我自己的捆綁插件,將包含我的分析器類,下面的pom.xml:CQ5如何在自定義插件

<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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>pl.mycompany.myproject</groupId> 
<artifactId>core</artifactId> 
<version>1.0.0-SNAPSHOT</version> 
<packaging>bundle</packaging> 

<name>core</name> 
<url>http://maven.apache.org</url> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.5</source> 
       <target>1.5</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>1.4.3</version> 
      <extensions>true</extensions> 
      <configuration> 
       <instructions> 
        <Export-Package>pl.mycompany.myproject.page.components.*;version=${pom.version}</Export-Package> 
       </instructions> 
      </configuration>     
     </plugin> 
    </plugins> 
</build> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.day.cq.wcm</groupId> 
     <artifactId>cq-wcm-api</artifactId> 
     <version>5.6.4</version> 
    </dependency> 
    <dependency> 
     <groupId>com.day.cq</groupId> 
     <artifactId>cq-commons</artifactId> 
     <version>5.6.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.sling</groupId> 
     <artifactId>org.apache.sling.api</artifactId> 
     <version>2.0.4-incubator</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.sling</groupId> 
     <artifactId>org.apache.sling.commons.json</artifactId> 
     <version>2.0.6</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-lang3</artifactId> 
     <version>3.0.1</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>xerces</groupId> 
     <artifactId>xercesImpl</artifactId> 
     <version>2.9.0</version> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

之後,我想創建類,將解析XML,我想用org.apache .xerces包。

我也創建了一個包含org.apache.xerces罐子其他包和我已經安裝了它,它在http://myhost.com:4502/system/console/bundles是有效的。

當我要聲明的Java類核心插件的DOMParser變量(上面的pom.xml):}

package pl.mycompany.myproject.page.components; 
import java.util.Date; 
import org.apache.sling.api.resource.Resource; 
import org.apache.xerces.parsers.DOMParser; 
enter code here 
public class EqAndSpecParser { 

private Resource resource; 

public EqAndSpecParser(Resource resource) { 
    this.resource = resource; 
} 

public void checkIfNeedToUpdate(Date lastModifiedDate, String lastGenerationDate, String xmlCode) { 
    try { 
     DOMParser parser = new DOMParser(); 
     parser.parse(xmlCode); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

public Resource getResource() { 
    return resource; 
} 

public void setResource(Resource resource) { 
    this.resource = resource; 
} 

然後我得到的錯誤/ CRX-快速啓動/日誌/:

FULL EXCEPTION: 
org.apache.sling.api.scripting.ScriptEvaluationException: An exception occurred processing JSP page /apps/myproject/components/specifications-and-equipment/specifications-and-equipment.jsp at line 16 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) 
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:508) 
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) 
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilterWithErrorHandling(WCMDebugFilter.java:184) 
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:151) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:244) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:254) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.dispatchRequest(SlingRequestProcessorImpl.java:294) 
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.dispatch(SlingRequestDispatcher.java:216) 
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.include(SlingRequestDispatcher.java:103) 
at com.day.cq.wcm.core.impl.WCMComponentFilter$ForwardRequestDispatcher.include(WCMComponentFilter.java:406) 
at org.apache.sling.scripting.jsp.taglib.IncludeTagHandler.dispatch(IncludeTagHandler.java:49) 
at org.apache.sling.scripting.jsp.taglib.AbstractDispatcherTagHandler.doEndTag(AbstractDispatcherTagHandler.java:129) 
at org.apache.jsp.libs.foundation.components.parsys.parsys_jsp._jspService(parsys_jsp.java:313) 
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:241) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:86) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:441) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) 
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:508) 
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) 
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilterWithErrorHandling(WCMDebugFilter.java:184) 
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:151) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:244) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:254) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.dispatchRequest(SlingRequestProcessorImpl.java:294) 
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.dispatch(SlingRequestDispatcher.java:216) 
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.include(SlingRequestDispatcher.java:103) 
at com.day.cq.wcm.core.impl.WCMComponentFilter$ForwardRequestDispatcher.include(WCMComponentFilter.java:406) 
at com.day.cq.wcm.tags.IncludeTag.includeResource(IncludeTag.java:224) 
at com.day.cq.wcm.tags.IncludeTag.doEndTag(IncludeTag.java:91) 
at org.apache.jsp.apps.myproject.components.contentpage_002d100_002d20_002d60_002d20.content_jsp._jspx_meth_cq_005finclude_005f3(content_jsp.java:276) 
at org.apache.jsp.apps.myproject.components.contentpage_002d100_002d20_002d60_002d20.content_jsp._jspService(content_jsp.java:174) 
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:241) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:86) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:441) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) 
at com.day.cq.wcm.tags.IncludeTag.includeScript(IncludeTag.java:167) 
at com.day.cq.wcm.tags.IncludeTag.doEndTag(IncludeTag.java:87) 
at org.apache.jsp.apps.myproject.components.page.body_jsp._jspx_meth_cq_005finclude_005f2(body_jsp.java:308) 
at org.apache.jsp.apps.myproject.components.page.body_jsp._jspService(body_jsp.java:228) 
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:241) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:86) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:441) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) 
at com.day.cq.wcm.tags.IncludeTag.includeScript(IncludeTag.java:167) 
at com.day.cq.wcm.tags.IncludeTag.doEndTag(IncludeTag.java:87) 
at org.apache.jsp.libs.foundation.components.page.page_jsp._jspx_meth_cq_005finclude_005f1(page_jsp.java:207) 
at org.apache.jsp.libs.foundation.components.page.page_jsp._jspService(page_jsp.java:161) 
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:241) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:86) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:441) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) 
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:508) 
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) 
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilterWithErrorHandling(WCMDebugFilter.java:184) 
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:151) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:244) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:254) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.dispatchRequest(SlingRequestProcessorImpl.java:294) 
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.dispatch(SlingRequestDispatcher.java:216) 
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.include(SlingRequestDispatcher.java:103) 
at com.day.cq.wcm.core.impl.WCMComponentFilter$ForwardRequestDispatcher.include(WCMComponentFilter.java:406) 
at org.apache.jsp.libs.foundation.components.primary.cq.Page.Page_jsp._jspService(Page_jsp.java:106) 
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:241) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:86) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:441) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) 
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:508) 
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) 
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:148) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:333) 
at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:160) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:254) 
at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) 
at com.day.cq.wcm.core.impl.warp.TimeWarpFilter.doFilter(TimeWarpFilter.java:106) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter.doFilter(RedirectFilter.java:290) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:59) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.doFilter(FormsHandlingServlet.java:220) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.theme.impl.ThemeResolverFilter.doFilter(ThemeResolverFilter.java:76) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.adobe.granite.optout.impl.OptOutFilter.doFilter(OptOutFilter.java:74) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.core.impl.WCMRequestFilter.doFilter(WCMRequestFilter.java:90) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter.doFilter(CanvasPageDeleteRequestFilter.java:87) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:83) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:127) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter.doFilter(BackgroundServletStarterFilter.java:135) 
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) 
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processRequest(SlingRequestProcessorImpl.java:151) 
at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:206) 
at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:96) 
at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:79) 
at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:42) 
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:49) 
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33) 
at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:127) 
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88) 
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76) 
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47) 
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33) 
at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:179) 
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88) 
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76) 
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47) 
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33) 
at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:259) 
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88) 
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76) 
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47) 
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33) 
at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:55) 
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88) 
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76) 
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47) 
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33) 
at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:75) 
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88) 
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76) 
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47) 
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33) 
at org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:48) 
at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:39) 
at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at com.day.j2ee.servletengine.ServletRuntimeEnvironment.service(ServletRuntimeEnvironment.java:250) 
at com.day.j2ee.servletengine.RequestDispatcherImpl.doFilter(RequestDispatcherImpl.java:321) 
at com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:340) 
at com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:383) 
at com.day.j2ee.servletengine.ServletHandlerImpl.process(ServletHandlerImpl.java:360) 
at com.day.j2ee.servletengine.HttpListener$Worker.run(HttpListener.java:644) 
at java.lang.Thread.run(Unknown Source) 
Caused by: org.apache.sling.api.SlingException: An exception occurred processing JSP page /apps/myproject/components/specifications-and-equipment/specifications-and-equipment.jsp at line 16 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:683) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:608) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:525) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:241) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:86) 
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:441) 
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) 
... 183 more 
Caused by: java.lang.NoClassDefFoundError: org/apache/xerces/parsers/DOMParser 
at org.apache.jsp.apps.myproject.components.specifications_002dand_002dequipment.specifications_002dand_002dequipment_jsp._jspService(specifications_002dand_002dequipment_jsp.java:165) 
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) 
... 188 more 
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.DOMParser not found by pl.mycompany.myproject.core [291] 
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1499) 
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75) 
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1882) 
at java.lang.ClassLoader.loadClass(Unknown Source) 
... 192 more 

DOMParser只是我想要使用的示例類。在項目中,我將需要使用外部罐從其他供應商,這只是POC。主要問題是:如何在CQ5中使用外部罐子?如何將它們安裝到CQ中,所有自定義插件都將使用這些罐子?

當我改變的Xerces依賴於

<dependency> 
    <groupId>xerces</groupId> 
    <artifactId>xercesImpl</artifactId> 
    <version>2.9.0</version> 
    <scope>compile</scope> 
</dependency> 

和我說<Embed-Dependency>xercesImpl;scope=compile</Embed-Dependency> 現在我得到錯誤,如:

25.09.2013 11:15:49.206 *INFO* [JcrInstaller.1] 
org.apache.sling.installer.provider.jcr.impl.JcrInstaller Registering resource with OSGi installer: [InstallableResource, priority=200, id=/apps/myproject/install/core-1.0.0-SNAPSHOT.jar] 
25.09.2013 11:15:49.231 *INFO* [OsgiInstallerImpl] pl.mycompany.myproject.core BundleEvent UNRESOLVED 
25.09.2013 11:15:49.231 *INFO* [OsgiInstallerImpl] pl.mycompany.myproject.core BundleEvent UPDATED 
25.09.2013 11:15:49.233 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Updated bundle pl.mycompany.myproject.core [291] from resource TaskResource(url=jcrinstall:/apps/myproject/install/core-1.0.0-SNAPSHOT.jar, entity=bundle:pl.mycompany.myproject.core, state=INSTALL, attributes=[org.apache.sling.installer.api.tasks.ResourceTransformer=:50:16:, Bundle-SymbolicName=pl.mycompany.myproject.core, Bundle-Version=1.0.0.SNAPSHOT], digest=1380100548768) 
25.09.2013 11:15:49.234 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Refreshing 1 bundles: [pl.mycompany.myproject.core [291]] 
25.09.2013 11:15:49.234 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Waiting up to 90 seconds for bundles refresh 
25.09.2013 11:15:49.234 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Done refreshing 1 bundles 
25.09.2013 11:15:49.234 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED 
25.09.2013 11:15:49.235 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED 
25.09.2013 11:15:49.235 *INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.BundleStartTask Could not start bundle pl.mycompany.myproject.core [291]. Reason: org.osgi.framework.BundleException: Unresolved constraint in bundle pl.mycompany.myproject.core [291]: Unable to resolve 291.34: missing requirement [291.34] osgi.wiring.package; (osgi.wiring.package=org.apache.xml.resolver). Will retry. 
25.09.2013 11:15:49.235 *INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.RestartActiveBundlesTask Unable to start bundle pl.mycompany.myproject.core [291] : Unresolved constraint in bundle pl.mycompany.myproject.core [291]: Unable to resolve 291.34: missing requirement [291.34] osgi.wiring.package; (osgi.wiring.package=org.apache.xml.resolver) 
25.09.2013 11:15:49.248 *INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.BundleStartTask Could not start bundle pl.mycompany.myproject.core [291]. Reason: org.osgi.framework.BundleException: Unresolved constraint in bundle pl.mycompany.myproject.core [291]: Unable to resolve 291.34: missing requirement [291.34] osgi.wiring.package; (osgi.wiring.package=org.apache.xml.resolver). Will retry. 
25.09.2013 11:15:49.249 *INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.RestartActiveBundlesTask Unable to start bundle pl.mycompany.myproject.core [291] : Unresolved constraint in bundle pl.mycompany.myproject.core [291]: Unable to resolve 291.34: missing requirement [291.34] osgi.wiring.package; (osgi.wiring.package=org.apache.xml.resolver) 

回答

4

包括外部JAR文件到您的包

的這部分你pom.xml中:

<dependency> 
    <groupId>xerces</groupId> 
    <artifactId>xercesImpl</artifactId> 
    <version>2.9.0</version> 
    <scope>provided</scope> 
</dependency> 

的xerces定義爲provided依賴性,例如。一個已經存在於CQ中。如果您要嵌入這種依賴性,範圍更改爲compile和使用<embed-dependency>選項Maven的捆綁插件,如:

<configuration> 
    <instructions> 
     <Export-Package>pl.mycompany.myproject.page.components.*;version=${pom.version}</Export-Package> 
     <Embed-Dependency>xercesImpl;scope=compile</Embed-Dependency> 
    </instructions> 
</configuration>     

此外,這是一個好主意,provided範圍添加到這實際上是所有依賴包括在CQ內(如cq-wcm-api等)。

解析個XML在CQ5

以上是直接回答你的問題(「如何使用外部JAR」)。然而,在這種特殊情況下,我不認爲你應該包括了Xerces庫,因爲它已經在JDK中存在。嘗試刪除了Xerces依賴和使用javax.xml.parsers API:

import javax.xml.parsers.*; 
... 
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance() 
DocumentBuilder builder = factory.newDocumentBuilder() 
builder.parse(new ByteArrayInputStream(xmlCode.getBytes())); 
+0

我已經改變了它,你寫的,但現在我得到我的安裝捆綁插件中其他錯誤: –

+0

細節在我的問題上面 –

+0

還有更不滿意的依賴,像'org.apache.xml.resolver'(你可以在'/ system/bundle'控制檯中看到它)。我已經用CQ5中解析XML的一般信息更新了我的答案。 –