MAXCOMPUTER一键注册包含第三方依赖的UDF函数

MAXCOMPUTER一键注册包含第三方依赖的UDF函数

在maven的pom文件中添加如下的打包插件依赖

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <minimizeJar>false</minimizeJar>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <!--打的包含依赖的jar包名字的后缀,默认是shaded-->
                            <shadedClassifierName>dep</shadedClassifierName>
                            <artifactSet>
                                <includes>
                                    <!-- Include here the dependencies you
                                        want to be packed in your fat jar -->
                                    <include>*:*</include>
                                </includes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>reference.conf</resource>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

上方的打包插件,会在target目录下面生成两个jar,我们只需要把结果是“-dep”的jar上传到odps上面,再注册udf函数即可。

等到上方插件下载完成,进行如下的操作:
在这里插入图片描述

如上图,在udf函数中,直接右键,选择 “deploy to server”,跳转到如下图:

在这里插入图片描述

在resource file 这一列,在结果直接加上“-dep”, 这个“maxcomputer-1.0-SNAPSHOT-dep.jar”这个其它就是idea中项目target目录下的jar包名称

函数注册成功大约需要20秒的时间,会有如下图的进度标志:
在这里插入图片描述

注意
1、idea如果使用的是社区版本,2018.1的社区版本使用上面的方法,是无法打包成功的。需更更新idea的版本,我这边将社区版更新到了2020版本,可以打包成功。如果idea是收费版,打包无影响
2、在打包过程中,maven界面可能会出现error,对结果无影响。出现error主要是自己的maven配置的问题,过20秒,会发现虽然maven报错了,但是函数仍然注册成功了

猜你喜欢

转载自blog.csdn.net/JAVA_LuZiMaKei/article/details/116229125