简体   繁体   English

Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder?

[英]Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder?

I have a simple Java Spring MVC web app.我有一个简单的 Java Spring MVC web 应用程序。 I build the WAR file using a Maven pom.xml file.我使用 Maven pom.xml 文件构建 WAR 文件。

When I do a "maven install", it produces a WAR file with my compiled Java classes in the /WEB-INFO/classes folder.当我执行“maven 安装”时,它会在/WEB-INFO/classes文件夹中生成一个带有我编译的 Java 类的 WAR 文件。

My maven pom.xml looks like this (dependencies commented out)...我的 maven pom.xml 看起来像这样(依赖项已注释掉)...

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mycompany.com</groupId>
    <artifactId>myapp</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>My Application</name>
    <url>http://maven.apache.org</url>
    <dependencies>

<!-- .... -->

    </dependencies>
    <build>
        <finalName>myapp</finalName>
    </build>
</project>

Next I want to obfuscate my Java classes (I'll be using Allatori obfuscater), so I'm thinking the easiest thing would be if my Java classes were all put into their own JAR file and stored in the /WEB-INF/lib folder with the rest of the JARs. Next I want to obfuscate my Java classes (I'll be using Allatori obfuscater), so I'm thinking the easiest thing would be if my Java classes were all put into their own JAR file and stored in the /WEB-INF/lib JARs 的 rest 文件夹。

Is there a way to modify my Maven pom.xml file so it will package of my classes up in a JAR and put the JAR in the /WEB-INF/lib folder? Is there a way to modify my Maven pom.xml file so it will package of my classes up in a JAR and put the JAR in the /WEB-INF/lib folder?

UPDATE:更新:

Adding this to the 'build' section (as suggested by "JF Meier" worked)...将此添加到“构建”部分(如“JF Meier”所建议的那样)......

    <build>
        <finalName>myapp</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <archiveClasses>true</archiveClasses>
                </configuration>
            </plugin>
        </plugins>

    </build>

You can use the <archiveClasses> configuration (set it to true ) to generate an additional jar with the classes.您可以使用<archiveClasses>配置(将其设置为true )生成带有类的附加 jar。

Also see:另见:

https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html

Move your Java classes in a separate Maven module and add that as a dependency to your WAR project.将您的 Java 类移动到单独的 Maven 模块中,并将其作为依赖项添加到您的 WAR 项目中。 Then you can do whatever is necessary creating the jar in that module.然后你可以做任何必要的事情,在该模块中创建 jar。

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

相关问题 将JAR文件添加到web-inf / lib文件夹中,而不将其包含在pom.xml中 - Add JAR-File to web-inf/lib folder without including it in pom.xml 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 如何将.class下的web-inf / classs打包为jar并将其放入web-inf / lib目录 - how to package the .class under the web-inf/classes as a jar and put it to the web-inf/lib dir UCP jar依赖项存在于pom.xml中,但未出现在WEB-INF \\ lib中 - UCP jar dependency present in pom.xml but its not appearing inside WEB-INF\lib 在POM的WEB-INF \ lib中添加jar - Adding a jar in WEB-INF\lib in POM Maven构建损坏/ WEB-INF / lib文件夹中的jar文件 - Maven build corrupting jar files in /WEB-INF/lib folder 使用Maven pom.xml在WAR中未创建除WEB-INF和META-INF以外的目录 - Directory not creating other than WEB-INF & META-INF in WAR using Maven pom.xml Jar maven依赖从我的WEB-INF / lib中消失 - Jar maven dependency disappears from my WEB-INF/lib 将MySQL连接器JAR放在我的WAR的WEB-INF / lib而不是$ CATALINA_HOME / common / lib中? - Place MySQL connector JAR in WEB-INF/lib of my WAR instead of in $CATALINA_HOME/common/lib? maven ear 插件没有从其中一场战争的 WEB-INF/lib 中复制所有 jar 文件 - maven ear plugin not copying all jar files from WEB-INF/lib of one of the war
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM