Maven插件 - 编辑目标文件(战争) [英] Maven plugin - edit files in target (war)

查看:212
本文介绍了Maven插件 - 编辑目标文件(战争)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一些小maven插件,我需要编辑目标的一些css和js文件(而不是来自src!)。我无法理解我能做到的阶段。

I am developing some little maven plugin and I need to edit some css and js files from target (not from src!). And I can't understand on what phase I can do it.

要访问src,我使用阶段:generate-resources 和以下代码:

To get access to src I use the phases:generate-resources and the following code:

MavenProject project = (MavenProject) getPluginContext().get("project");
String projectDir=project.getBasedir().toString();

如果在那里复制了所有的js,css文件但是没有生成war文件,我怎样才能获得目标为了编辑目标中的一些文件并通过js和css文件的一些修改获得最终战争?

How can I get target when all js,css files are copied there but war file is not generated in order to edit some files from target and get final war with some modifications of js and css files?

编辑

我需要什么呢我的项目中有js文件:a.js,b.js.我想通过maven来混淆它们。我的意思是,当我构建项目时,混淆。当然,最终战争中的所有文件都必须进行模糊处理,但src中的相同文件必须保持未经过模糊处理。
此外,我需要将一些混淆的文件合并到一个文件中。

EDIT
What for I need it. I have js files in my project: a.js, b.js. I want to obfuscate them via maven. I mean, obfuscate when I build project. And of course all files in final war must be obfuscated but the same files in src must be left unobfuscated. Besides, I need to combine some obfuscated files into one file.

推荐答案

我找到了答案。问题是我们必须在prepare-package和package阶段之间添加一些逻辑。当我们使用maven-war-plugin时,我们可以使用爆炸目标来实现。来自官方文档:

I found the answer. The problem is that we must add some logic between "prepare-package" and "package" phases. As we user maven-war-plugin we can do it using exploded goal. From official docs:


在指定目录中创建爆炸的webapp。

Create an exploded webapp in a specified directory.

这里有必要记住一个重要的事情,即版本2.0.1后的maven复制资源两次,所以如果我们想要使用maven 2.5,我们必须使用< useCache> true< / useCache将> 。所以最终解决方案:

And here it's necessary to remember one important thing that maven after version 2.0.1 copies resources twice so if we want to use maven 2.5 we must use <useCache>true</useCache>. So final solution:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.5</version>
  <executions>
    <execution>
      <id>prepare-war</id>
      <phase>prepare-package</phase>
        <goals>
          <goal>exploded</goal>
        </goals>
    </execution>
  </executions>
  <configuration>
    <useCache>true</useCache>    
 </configuration>
</plugin>

<plugin>
    <groupId>my plugin</groupId>
    <artifactId>...</artifactId>
    <version>....</version>
    <executions>
    <execution>
        <phase>prepare-package</phase>
        <goals>
            <goal>...</goal>
        </goals>
        </execution>
    </executions>
</plugin>

这篇关于Maven插件 - 编辑目标文件(战争)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆