Reputation: 33
I have created a xml file with specific configuration for my jndi datasource, like this:
<?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>
Dropped this file on $JETTY_BASE/etc but Jetty doesn't seem to be able to read the file to configure the datasource. However, if i pick the "New" tag and copy it to the jetty.xml file, it works.
I want this in a separate file so it makes easier for deploying to production and also to use this file in jetty-maven-plugin.
Is this possible? What am I doing wrong?
Upvotes: 1
Views: 2409
Reputation: 49515
Jetty will only read what its been told to read based on the configuration.
You can see what that would be using the --list-config
command line option.
Example:
[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
As you can see only the above XML files are read.
Lets say we add a ${jetty.base}/etc/my-datasource.xml
, we would also need to tell jetty to use that xml.
Manually we can add it to the ${jetty.base}/start.ini
or create a new file with any name you want such as ${jetty.base}/start.d/mydatasource.ini
.
Example:
[new-base]$ cat start.d/mydatasource.ini
etc/mydatasource.xml
Now when you ask, you'll see it listed ...
[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
Upvotes: 3