如何让 Jetty 读取新的 jetty-xxx.xml 文件
How to make Jetty read new jetty-xxx.xml files
我已经为我的 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 似乎无法读取该文件来配置数据源。但是,如果我选择 "New" 标签并将其复制到 jetty.xml 文件,它会起作用。
我想把它放在一个单独的文件中,这样可以更容易地部署到生产环境中,也可以在 jetty-maven-plugin 中使用这个文件。
这可能吗?我做错了什么?
Jetty 只会根据配置读取它被告知要读取的内容。
您可以使用 --list-config
命令行选项查看会发生什么。
示例:
[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
,我们还需要告诉码头使用那个 xml。
我们可以手动将其添加到 ${jetty.base}/start.ini
或使用您想要的任何名称创建一个新文件,例如 ${jetty.base}/start.d/mydatasource.ini
.
示例:
[new-base]$ cat start.d/mydatasource.ini
etc/mydatasource.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
${jetty.base}/etc/mydatasource.xml
我已经为我的 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 似乎无法读取该文件来配置数据源。但是,如果我选择 "New" 标签并将其复制到 jetty.xml 文件,它会起作用。
我想把它放在一个单独的文件中,这样可以更容易地部署到生产环境中,也可以在 jetty-maven-plugin 中使用这个文件。
这可能吗?我做错了什么?
Jetty 只会根据配置读取它被告知要读取的内容。
您可以使用 --list-config
命令行选项查看会发生什么。
示例:
[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
,我们还需要告诉码头使用那个 xml。
我们可以手动将其添加到 ${jetty.base}/start.ini
或使用您想要的任何名称创建一个新文件,例如 ${jetty.base}/start.d/mydatasource.ini
.
示例:
[new-base]$ cat start.d/mydatasource.ini
etc/mydatasource.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
${jetty.base}/etc/mydatasource.xml