1、编写java 常量类并打包成jar包

package com.example.proj;

public class Hello {

    public static String hello(String toWhom) {
        return "Hello, " + toWhom + "!";
    }

}

2、把打包好的jar放到 postgresql所在服务器的 /opt 目录

安装jar

select sqlj.install_jar('file:///opt/CountIntegr-1.0-SNAPSHOT.jar', 'examples', true);

3、映射逻辑名examples到public模式

 SELECT sqlj.set_classpath('public', 'examples');

4、查询映射是否成功

 select sqlj.get_classpath('public');

5、创建函数

create or replace function say_hello(varchar) 
returns varchar
as 'com.example.proj.Hello.hello' language java;
language java;

6、使用

select say_hello('Lining');

7、用到的一些函数:

更新jar包

select sqlj.replace_jar('file:///opt/CountIntegr-1.0-SNAPSHOT.jar', 'examples', true);

删除jar包

select sqlj.remove_jar('communitydb',true);

8、如果引用了第三方jar,注意pom配置,一个实例如下

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>face</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv-platform</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.0.0</version>
        </dependency>
        <dependency>
            <groupId>opencv</groupId>
            <artifactId>opencv</artifactId>
            <version>4.4.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <!-- 这个archive以及archive里面的设置很重要,没有这个配置,就无法生成可执行jar文件 -->
                    <archive>
                        <manifest>
                            <mainClass>com.example.proj.Compare</mainClass>
                        </manifest>
                    </archive>
                    <!-- 这个jar-with-dependencies是这个插件中预置的,不用管它,尽管用就好了 -->
                    <!-- 当然,你也可以用自己的descriptor。如何用?自己去查这个插件的文档 -->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- 这里的phase和goals都是maven的基础概念,不懂的可以去看maven的文档 -->
                        <!-- 总之,当你install你的project的时候,是会涵盖package phase和single goal的 -->
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

 

最后修改于 2020-08-03 19:07:18
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇