简体   繁体   English

如何将外部文件夹添加到Jetty的类路径

[英]How to add external folder to Jetty's classpath

I am trying to add an external folder, setup/ , to my Jetty's classpath. 我试图将外部文件夹setup/添加到我的Jetty的类路径中。 I can successfully add the setup folder to its classpath inside of its launch configurations in eclipse. 我可以成功地添加setup文件夹的类路径中其内部launch configurations在Eclipse中。 I need to instead give it the setup folder's path as an argument to Jetty because I don't have control of the launch configurations when I run my project outside of an eclipse environment. 相反,我需要给它提供setup文件夹的路径作为Jetty的参数,因为当我在Eclipse环境之外运行项目时,我无法控制launch configurations I've tried stuff like this in the XML: 我已经在XML中尝试过这样的事情:

<jvmarg value="-Dpath=${DbServer.location}/setup"/>

This does not do anything... Any help is appreciated, thanks! 这什么也没做...感谢您的任何帮助,谢谢!

The issue is that the setup folder is in the WAR directory, so even pointing to anything else as the classpath will not make changes to where Jetty will look for the folder. 问题在于setup文件夹位于WAR目录中,因此即使指向其他内容,因为类路径也不会更改Jetty查找文件夹的位置。 Look here for how Jetty uses its classpath: 在这里查看Jetty如何使用其类路径:

Jetty ClassLoading 码头类装载

Classes contained within WEB-INF/lib or WEB-INF/classes have priority over classes on the parent class loader. WEB-INF/libWEB-INF/classes包含的WEB-INF/classes优先级高于父类加载器上的类。 This is the opposite of the normal behaviour of a java 2 class loader. 这与Java 2类加载器的正常行为相反。

As an example, to run it with the help of Maven ( jetty-maven-plugin ) : 例如,要在Maven( jetty-maven-plugin )的帮助下运行它:

        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.4.7.v20170914</version>
            <configuration>
                <httpConnector>
                    <port>8095</port>
                </httpConnector>
                <webApp>
                    <contextPath>/</contextPath>
                    <extraClasspath>conf/</extraClasspath>
                </webApp>
            </configuration>
        </plugin>

Then run your webapp with mvn jetty:run 然后使用mvn jetty:run运行您的web应用mvn jetty:run

At the root of my project, I have a ./conf/ directory, including some properties or xml files. 在项目的根目录下,我有一个./conf/目录,其中包括一些属性或xml文件。

Some configuration properties for can be found at Configuring Your WebApp , but you can find undocumented properties in the class org.eclipse.jetty.webapp.WebAppContext or in org.eclipse.jetty.maven.plugin.JettyWebAppContext (its subclass). 对于一些配置属性,可以发现配置你的web应用 ,但你可以找到在类无证性质 org.eclipse.jetty.webapp.WebAppContextorg.eclipse.jetty.maven.plugin.JettyWebAppContext (它的子类)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM