简体   繁体   中英

Define context elements in tomcat7-maven-plugin

I am trying to display images located in some folder outside of my app using tomcat7-maven-plugin. I ran into this article: https://howtoprogramwithjava.com/how-to-display-images-stored-on-a-server/ It is said that a way to go is to create an xml file defining the context path in tomcat's conf\\Catalina\\localhost directory. However, I am using tomcat7-maven-plugin, so I can't find the specified location in there. And I have no idea how to configure it in pom.xml if it's even possible. Thank you all in advance!

You can have a context.xml file in your webapp/META-INF folder like

src
 main
  webapp
   META-INF
    context.xml
   WEB-INF

with content that you wish to have.

Or you can add the allowLinking attribute to Context section and in webapp folder create a soft link to the image folder use command ln -s .

If you want to package the resource to you app war , you can specify it as web resources

<build>
<plugins>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>  

                <webResources>
                    <resource>
<!-- this is relative to the pom.xml directory  where can find your images -->

                      <directory>${project.basedir}/src/main/resources
                        </directory>

                    </resource>
                </webResources>    
                <warName>yourwarname</warName>
            </configuration>
        </plugin>
</plugins>
</build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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