简体   繁体   English

Maven:将 war/web-inf/classes 中的类作为 jar 添加到 war/web-inf/lib

[英]Maven: Adding classes from war/web-inf/classes as a jar to war/web-inf/lib

I'm rather new to maven here.我对 maven 很陌生。 I have created a Maven Spring boot project with following structure -我创建了一个具有以下结构的 Maven Spring boot 项目 -

..
<groupId>com.example</groupId>
<artifactId>MavenWeb</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>

<name>MavenWeb</name>
<description>Maven Test Web Application</description>

<dependencies>
 ..

As you can see the packaging has been set as war .如您所见, packaging已设置为war As such when the war file is generated, my source code's generated .class files are generated in the war/web-inf/classes folder.因此,当生成war文件时,我的源代码生成的.class files会在war/web-inf/classes文件夹中生成。 Rather than it being generated in classes folder, I'd like to generate it as jar file and maintain it in war/web-inf/lib folder.我想将其生成为jar文件并将其维护在war/web-inf/lib文件夹中,而不是在 classes 文件夹中生成。

I'm guessing I need to make use of the maven-jar-plugin for this.我猜我需要为此使用maven-jar-plugin But I'm not sure how to move the generated jar to war/web-inf/lib directory?但我不确定如何将生成的 jar 移动到war/web-inf/lib目录? Is there a simpler alternative to this?有没有更简单的替代方法?

Also how can I restrict the .class files from being generated in war/web-inf/classes folder?另外,如何限制在war/web-inf/classes文件夹中生成.class文件?

Would really appreciate some pointers.真的很感激一些指点。 Many thanks.非常感谢。

This is how the build section of pom should be -这就是 pom 的build部分应该如何 -

<groupId>com.example</groupId>
<artifactId>MavenWeb</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>

<name>MavenWeb</name>
<description>Maven Test Web Application</description>

<build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archiveClasses>true</archiveClasses>
                    <webResources>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                            <artifactId>${project.artifactId}</artifactId>
                            <groupId>${project.groupId}</groupId>
                            <version>${project.version}</version>
                            <file>
                                ${project.build.directory}/${project.artifactId}-${project.version}.jar
                            </file>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

This would restrict the compiled classes from being generated in classes folder while at the same time generate a thin jar of the compiled classes and add it as web-inf/lib/MavenWeb-0.0.1.jar .这将限制在 classes 文件夹中生成已编译的类,同时生成已编译类的瘦 jar 并将其添加为web-inf/lib/MavenWeb-0.0.1.jar

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

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