如何使Jetty读取新的jetty-xxx.xml文件

时间:2018-06-27 14:28:14

标签: jetty

我为jndi数据源创建了具有特定配置的xml文件,如下所示:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
        <Configure id="Server" class="org.eclipse.jetty.server.Server">
            <New id="MyDB" class="org.eclipse.jetty.plus.jndi.Resource">
                <Arg></Arg>
                <Arg>jdbc/MyDB</Arg>
                <Arg>
                    <New class="com.mysql.cj.jdbc.MysqlConnectionPoolDataSource">
                        <Set name="url">******</Set>
                        <Set name="user">******</Set>
                        <Set name="password">******</Set>
                    </New>
                </Arg>
            </New>
        </Configure>

将此文件拖放到$ JETTY_BASE / etc上,但是Jetty似乎无法读取该文件来配置数据源。但是,如果我选择“新建”标签并将其复制到jetty.xml文件中,它将起作用。

我希望将此文件保存在一个单独的文件中,以便更轻松地部署到生产环境以及在jetty-maven-plugin中使用此文件。

这可能吗?我在做什么错了?

1 个答案:

答案 0 :(得分:0)

Jetty将仅根据配置读取要告知的内容。

使用CREATE OR REPLACE PACKAGE BODY kcp_Rep_Pla AS -- TYPES -- VARIABLES GLOBALES -- CONSTANTES -- CURSORES -- FUNCIONES FUNCTION Fup_Val_Tbcaracter(P_INDICE PLS_INTEGER) RETURN VARCHAR2 IS -- vcResultado Varchar2(4000) := Null; -- BEGIN -- vcResultado := tbCaracter(P_INDICE); RETURN vcResultado; -- EXCEPTION WHEN no_data_found THEN -- RETURN NULL; -- END; -- -- FUNCTION Fup_Val_Tbnumero(P_INDICE PLS_INTEGER) RETURN NUMBER IS -- vcResultado NUMBER := Null; -- BEGIN -- vcResultado := tbNumero(P_INDICE); RETURN vcResultado; -- EXCEPTION WHEN no_data_found THEN -- RETURN NULL; -- END; -- FUNCTION Fup_Val_Tbfecha(P_INDICE PLS_INTEGER) RETURN DATE IS -- vcResultado DATE := Null; -- BEGIN -- vcResultado := tbFecha(P_INDICE); RETURN vcResultado; -- EXCEPTION WHEN no_data_found THEN -- RETURN NULL; -- END; -- FUNCTION Fup_HTML_Table(P_CONSULTA VARCHAR2 ,P_ENCABEZADO VARCHAR2 DEFAULT 'N') RETURN VARCHAR2 IS -- vcResultado varchar2(4000) := Null; vcConsulta varchar2(4000) := Null; vcHTML varchar2(32767); nmIndice number := 1; nmCaracteres number := 3898; cuCursor SYS_REFCURSOR; lRetVal CLOB; lHTMLOutput XMLType; lXSL CLOB; lXMLData XMLType; lContext DBMS_XMLGEN.CTXHANDLE; nmLength number := 0; l_offset NUMBER := 1; -- BEGIN -- OPEN cuCursor FOR P_CONSULTA; -- get a handle on the ref cursor -- lContext := DBMS_XMLGEN.NEWCONTEXT(cuCursor); -- -- setNullHandling to 1 (or 2) to allow null columns to be displayed -- DBMS_XMLGEN.setNullHandling(lContext,1); -- create XML from ref cursor -- lXMLData := DBMS_XMLGEN.GETXMLTYPE(lContext,DBMS_XMLGEN.NONE); -- this is a generic XSL for Oracle's default XML row and rowset tags -- -- " " is a non-breaking space -- lXSL := lXSL || q'[<?xml version="1.0" encoding="ISO-8859-1"?>]'; lXSL := lXSL || q'[<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">]'; lXSL := lXSL || q'[ <xsl:output method="html"/>]'; lXSL := lXSL || q'[ <xsl:template match="/">]'; -- lXSL := lXSL || q'[ <html>]'; -- lXSL := lXSL || q'[ <body>]'; --lXSL := lXSL || q'[<table border="0" cellspacing="0" cellpadding="1" style="width:100.0%;font-size:14px;" width="100%">]'; IF P_ENCABEZADO = 'S' THEN -- lXSL := lXSL || q'[<tr align="center">]'; lXSL := lXSL || q'[<xsl:for-each select="/ROWSET/ROW[1]/*">]'; lXSL := lXSL || q'[<th><xsl:value-of select="name()"/></th>]'; lXSL := lXSL || q'[</xsl:for-each>]'; lXSL := lXSL || q'[</tr>]'; -- END IF; -- lXSL := lXSL || q'[<xsl:for-each select="/ROWSET/*">]'; lXSL := lXSL || q'[<tr>]'; lXSL := lXSL || q'[<xsl:for-each select="./*">]'; lXSL := lXSL || q'[<td><xsl:value-of select="text()"/> </td>]'; lXSL := lXSL || q'[</xsl:for-each>]'; lXSL := lXSL || q'[</tr>]'; lXSL := lXSL || q'[</xsl:for-each>]'; --lXSL := lXSL || q'[</table>]'; -- lXSL := lXSL || q'[ </body>]'; -- lXSL := lXSL || q'[ </html>]'; lXSL := lXSL || q'[ </xsl:template>]'; lXSL := lXSL || q'[</xsl:stylesheet>]'; -- XSL transformation to convert XML to HTML -- lHTMLOutput := lXMLData.transform(XMLType(lXSL)); -- convert XMLType to Clob -- lRetVal := lHTMLOutput.getClobVal(); --Raise_application_error(-20001,'uno'||lRetVal); -- nmLength := DBMS_LOB.getlength (lRetVal); -- FOR i IN 1 .. 1000 LOOP -- tbCaracter(i) := Null; -- END LOOP; -- LOOP EXIT WHEN l_offset > nmLength ; -- tbCaracter(nmindice) := DBMS_LOB.SUBSTR (lRetVal,nmCaracteres,l_offset); nmindice := nmindice + 1; l_offset := l_offset + nmCaracteres; -- If nmindice=3 Then -- Raise_Application_Error(-20001,tbCaracter(2)); -- End If; -- END LOOP; -- RETURN SUBSTR(Fup_Val_Tbcaracter(1),1,nmCaracteres); -- END; -- FUNCTION Fup_HTML_Length(P_CONSULTA VARCHAR2 ,P_ENCABEZADO VARCHAR2 DEFAULT 'N') RETURN NUMBER IS -- vcResultado varchar2(4000) := null; vcConsulta varchar2(4000) := null; vchtml varchar2(32767); cuCursor SYS_REFCURSOR; lRetVal CLOB; lHTMLOutput XMLType; lXSL CLOB; lXMLData XMLType; lContext DBMS_XMLGEN.CTXHANDLE; nmLength number := 0; -- BEGIN -- OPEN cuCursor FOR P_CONSULTA; -- get a handle on the ref cursor -- lContext := DBMS_XMLGEN.NEWCONTEXT(cuCursor); -- -- setNullHandling to 1 (or 2) to allow null columns to be displayed -- DBMS_XMLGEN.setNullHandling(lContext,1); -- create XML from ref cursor -- lXMLData := DBMS_XMLGEN.GETXMLTYPE(lContext,DBMS_XMLGEN.NONE); -- this is a generic XSL for Oracle's default XML row and rowset tags -- -- " " is a non-breaking space -- lXSL := lXSL || q'[<?xml version="1.0" encoding="ISO-8859-1"?>]'; lXSL := lXSL || q'[<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">]'; lXSL := lXSL || q'[ <xsl:output method="html"/>]'; lXSL := lXSL || q'[ <xsl:template match="/">]'; -- lXSL := lXSL || q'[ <html>]'; -- lXSL := lXSL || q'[ <body>]'; lXSL := lXSL || q'[ <table border="0" cellspacing="0" cellpadding="0">]'; IF P_ENCABEZADO = 'S' THEN -- lXSL := lXSL || q'[ <tr>]'; lXSL := lXSL || q'[ <xsl:for-each select="/ROWSET/ROW[1]/*">]'; lXSL := lXSL || q'[ <th><xsl:value-of select="name()"/></th>]'; lXSL := lXSL || q'[ </xsl:for-each>]'; lXSL := lXSL || q'[ </tr>]'; -- END IF; -- lXSL := lXSL || q'[ <tr><td><ul>]'; lXSL := lXSL || q'[ <xsl:for-each select="/ROWSET/*">]'; lXSL := lXSL || q'[ <xsl:for-each select="./*">]'; lXSL := lXSL || q'[ <li><xsl:value-of select="text()"/></li>]'; lXSL := lXSL || q'[ </xsl:for-each>]'; lXSL := lXSL || q'[ </xsl:for-each>]'; lXSL := lXSL || q'[ </ul></td></tr>]'; lXSL := lXSL || q'[ </table>]'; -- lXSL := lXSL || q'[ </body>]'; -- lXSL := lXSL || q'[ </html>]'; lXSL := lXSL || q'[ </xsl:template>]'; lXSL := lXSL || q'[</xsl:stylesheet>]'; -- XSL transformation to convert XML to HTML -- lHTMLOutput := lXMLData.transform(XMLType(lXSL)); -- convert XMLType to Clob -- lRetVal := lHTMLOutput.getClobVal(); -- nmLength := DBMS_LOB.getlength (lRetVal); -- CLOSE cuCursor; RETURN nmLength; -- EXCEPTION WHEN OTHERS THEN -- CLOSE cuCursor; RETURN NULL; -- END; END kcp_Rep_Pla; / 命令行选项,您会看到什么。

示例:

--list-config

如您所见,仅读取上述XML文件。

让我们说我们添加一个[new-base]$ java -jar ../jetty-home-9.4.11.v20180605/start.jar --list-config ...(snip lots of output)... Jetty Active XMLs: ------------------ ${jetty.home}/etc/jetty-threadpool.xml ${jetty.home}/etc/jetty.xml ${jetty.home}/etc/jetty-webapp.xml ${jetty.home}/etc/jetty-plus.xml ${jetty.home}/etc/jetty-annotations.xml ${jetty.home}/etc/jetty-deploy.xml ${jetty.home}/etc/jetty-http.xml ${jetty.home}/etc/jetty-jmx.xml ,我们还需要告诉码头使用该xml。

我们可以手动将其添加到${jetty.base}/etc/my-datasource.xml或使用您想要的任何名称(例如${jetty.base}/start.ini)创建新文件。

示例:

${jetty.base}/start.d/mydatasource.ini

现在,当您问时,您会看到它列出...

[new-base]$ cat start.d/mydatasource.ini
etc/mydatasource.xml