To shade or not to shade

2 篇文章 0 订阅

你的项目需要使用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);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Shade Matlab是一种在Matlab软件中使用的灰度变换方法,它可以将一幅灰度图像的像素值映射到另一幅灰度图像上,从而实现调整图像的对比度和亮度。在实际应用中,Shade Matlab主要用于图像增强、图像处理、目标检测等领域。具体来说,通过设置Shade Matlab中的参数,可以实现对图像亮度和对比度的不同调整,达到不同的目的。其中,亮度的增加会使得图像变得更明亮,而亮度的减少则会使图像变得更暗。而对比度的增加则会增强图像的细节和纹理,使得图像更加清晰。需要注意的是,在使用Shade Matlab进行图像处理时,需要根据实际情况合理设置参数以达到最佳效果,同时还需要对处理结果进行评估和验证。总之,Shade Matlab是Matlab软件中非常有用的一个图像处理工具,可以帮助用户在图像处理中取得更好的效果。 ### 回答2: Shade Matlab是一个Matlab函数库,它可以生成高质量的渐变/阴影图形。该库包括多种渐变/阴影形状,例如矩形、椭圆、多边形等,并且支持自定义形状。使用Shade Matlab还可以定义渐变/阴影的颜色、方向、透明度等属性,以满足不同的绘图需求。 除此之外,Shade Matlab还提供了多种绘图方法,例如绘制等高线图、绘制地形图、绘制3D渐变图等。这些图形可以用于各种应用领域,例如地理信息系统、气象学、生态学等。 总之,Shade Matlab是一个功能强大的Matlab函数库,它可以帮助用户轻松地生成多种高质量的渐变/阴影图形。无论是初学者还是专业人士,都可以受益于这个库的使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值