[英]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.