To shade or not to shade

你的项目需要使用Joda2.1,但是Elasticsearch 2.0.0-beta2 要求使用Joda2.8

<properties>
    <elasticsearch.version>2.0.0-beta2</elasticsearch.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>shield</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.1</version>
    </dependency>
</dependencies>
<properties>
    <elasticsearch.version>2.0.0-beta2</elasticsearch.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>shield</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.1</version>
    </dependency>
</dependencies>

遮罩ES

新建一个maven工程,pom.xml如下:

<groupId>my.elasticsearch.test</groupId>
<artifactId>es-shaded</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
    <elasticsearch.version>2.0.0-beta2</elasticsearch.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>shield</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>elasticsearch-releases</id>
        http://maven.elasticsearch.org/releases
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<groupId>my.elasticsearch.test</groupId>
<artifactId>es-shaded</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
    <elasticsearch.version>2.0.0-beta2</elasticsearch.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>shield</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>elasticsearch-releases</id>
        http://maven.elasticsearch.org/releases
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

遮罩并且重定位冲突的包

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <relocations>
                            <relocation>
                                <pattern>org.joda</pattern>
                                <shadedPattern>my.elasticsearch.joda</shadedPattern>
                            </relocation>
                        </relocations>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <relocations>
                            <relocation>
                                <pattern>org.joda</pattern>
                                <shadedPattern>my.elasticsearch.joda</shadedPattern>
                            </relocation>
                        </relocations>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

运行 mvn clean install 将会创建遮罩后的Elasticsearch版本。Joda2.8也被遮罩起来了

现在你可以同时使用Elasticsearch 2.0.0-beta2和Joda2.1了

<!-- This artifact contains all elasticsearch libs including the shaded version of Joda and Shield -->
<dependency>
    <groupId>my.elasticsearch.test</groupId>
    <artifactId>es-shaded</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency> <!-- You still use your own Joda version -->
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.1</version>
</dependency>

使用你自己的版本的Joda,只需要import org.joda.time.DateTime
使用遮罩后版本的Joda,importing my.elasticsearch.joda.time.DateTime,不过一般不建议这样做
因为debug的时候跟源码对不上?

// import org.joda.time.DateTime;
// import my.elasticsearch.joda.time.DateTime;
CodeSource codeSource = new org.joda.time.DateTime().getClass().getProtectionDomain().getCodeSource();
System.out.println("unshaded = " + codeSource);
codeSource = new my.elasticsearch.joda.time.DateTime().getClass().getProtectionDomain().getCodeSource();
System.out.println("shaded = " + codeSource);
时间: 2024-09-20 04:12:35

To shade or not to shade的相关文章

jquery放大镜效果超漂亮噢_jquery

这个放大镜的代码挺简单滴效果也不错. 复制代码 代码如下: <script> //QQ:496928838 微凉 $(function(){ $("#demo").enlarge( { // 鼠标遮罩层样式 shadecolor: "#FFD24D", shadeborder: "#FF8000", shadeopacity: 0.4, cursor: "move", // 大图外层样式 layerwidth: 4

如何获取、安装和制作 GTK 主题

多数桌面版 Linux 都支持主题.GUI(LCTT 译注:图形用户界面)独有的外观或者"风格"叫做主题.用户可以改变主题让桌面看起来与众不同.通常,用户也会更改图标,然而,主题和图标包是两个独立的实体.很多人想制作他们自己的主题,因此这是一篇关于 GTK 主题的制作以及各种制作时所必需的信息的文章. 注意: 这篇文章着重讨论 GTK3,但会稍微谈一下 GTK2.Metacity 等.本文不会讨论光标和图标. 基本概念 GIMP 工具包(简称 GTK)是一个用来在多种系统上(因此造就了

Maven实战

Maven 实战 许晓斌  著 本书由国内社区公认的Maven专家Juven Xu亲自执笔,内容的权威性毋庸置疑. 本书是国内第一本公开出版的Maven专著.它内容新颖,基于最新发布的Maven 30,不仅详尽讲解了Maven 30的所有新功能和新特性,而且还将这些新功能和新特性与Maven 2x版本进行了对比,以便于正在使用Maven 2x版本的用户能更好地理解.本书内容全面,以从专家的角度阐释Maven的价值开篇,全面介绍了Maven的安装.配置和基本使用方法,以便于初学者参考:详细

XML入门教程:XML 浏览器支持

xml|教程|浏览器|入门教程 几乎所有的主流浏览器均支持XML和XSLT. Mozilla Firefox 从1.0.2版本开始,Firefox就已开始支持XML和XSLT(包括CSS). Mozilla Mozilla含有用于XML解析的Expat,并支持显示XML + CSS.Mozilla同时拥有对Namespaces的某些支持. Mozilla同样可做到对XSLT的执行(XSLT implementation). Netscape 自从版本8开始,Netscape开始使用Mozilla

水平细线的几种制作方法

一.水平线法 1.在 Dreamweaver 中新建一个文档,插入一条水平线,双击水平线,调出属性面板. 2.在水平线的属性面板上设置高度 H = 0 pixel. 3.Copy 此条水平线,在属性面板中把 Shade 的勾点掉. 4.按 F12 进行预览,请对比下面的(1)(2)源代码及效果. (1) 源代码:<hr size="0" color="#3366FF" noshade> (2) 源代码: <hr size="0"

分析总结一下<li>和<hr>的样式定义

编者注:本来之前我打算写表现本文主题的文章,但最近在新浪博客群中看到了这篇文章,就不用我多费心血了,这里转载过来,希望对大家有所帮助. li {list-style-image: url(images/disc.gif);} li的这个样式定义是将列表项目使用图片来代替显示的小圆点.当然您也可以显示成其它效果,详细请参阅下面的定义: 列表项目效果的CSS定义 *list-style-type: circle(可换成自己想要的样式); 列表项目样式 disc : CSS1 实心圆 circle :

FileSystemObject 示例代码

filesystemobject|示例 在本节描述的示例代码,提供真实的例子来示范在 FileSystemObject 对象模式中可用的许多功能.该代码显示了如何一起使用对象模式的所有功能,以及如何在您自己的代码中有效地使用这些功能. 请注意,由于该代码是极一般的,所以要使该代码能够真正在您的机器上运行,可能需要一些其他代码和小小的变更.这些改变之所以必要,是因为在 Active Server Pages 和 Windows Scripting Host 之间,为输入和输出给用户采用了不同的方法

实例学习:网页中用CSS定义<li>和<hr>的样式

css|网页 本来之前我打算写表现本文主题的文章,但最近在新浪博客群中看到了这篇文章,就不用我多费心血了,这里转载过来,希望对大家有所帮助. li {list-style-image: url(images/disc.gif);} li的这个样式定义是将列表项目使用图片来代替显示的小圆点.当然您也可以显示成其它效果,详细请参阅下面的定义: 列表项目效果的CSS定义 *list-style-type: circle(可换成自己想要的样式); 列表项目样式 disc : CSS1 实心圆 circl

详细讲解列表项目和水平线在CSS中的定义

css|项目 本教程主要讲解了网页常用标签<li>和<hr>的样式的定义.希望对大家有所帮助. li {list-style-image: url(images/disc.gif);} li的这个样式定义是将列表项目使用图片来代替显示的小圆点.当然您也可以显示成其它效果,详细请参阅下面的定义: 列表项目效果的CSS定义 *list-style-type: circle(可换成自己想要的样式); 列表项目样式 disc : CSS1 实心圆 circle : CSS1 空心圆 squ