Movatterモバイル変換


[0]ホーム

URL:


Fork me on GitHub

junixsocket — Unix Domain Sockets for Java


  • Last Published: 2024-09-23|
  • Version: 2.10.1
Built by Maven

Add junixsocket to your project

Below are instructions how to add junixsocket via Maven, Gradle, or plain JAR files to your project.

There are also examples how to add junixsocket to your JDBC connection, so you can connect to yourdatabase via unix sockets.

Maven dependencies

Common dependency

Add the following dependency to your Maven project

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-core</artifactId>  <version>2.10.1</version>  <type>pom</type></dependency>

IMPORTANT: Make sure to include the<type>pom</type> line (this has changed in junixsocket 2.4.0).

Some applications may have problems with this POM dependency. You can also manually specify thefollowing two dependencies instead:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-common</artifactId>  <version>2.10.1</version></dependency>

and

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-native-common</artifactId>  <version>2.10.1</version></dependency>

Optional dependencies

If you're going to use AFUNIXSocketServer code, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-server</artifactId>  <version>2.10.1</version></dependency>

If you're going to use RMI over Unix sockets, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-rmi</artifactId>  <version>2.10.1</version></dependency>

If you're going to use the mySQL Connector for Unix sockets, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-mysql</artifactId>  <version>2.10.1</version></dependency>

If you're going to use TIPC, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-tipc</artifactId>  <version>2.10.1</version></dependency>

If you're going to use VSOCK, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-vsock</artifactId>  <version>2.10.1</version></dependency>

If you're going to use the Jetty connectors, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-jetty</artifactId>  <version>2.10.1</version></dependency>

If you're going to use the SSL extension, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-ssl</artifactId>  <version>2.10.1</version></dependency>

(On Android, you may also want to addorg.bouncycastle:bcprov-jdk18on andorg.bouncycastle:bctls-jdk18on, since the default SSL implementation is incomplete)

If you're going to use Darwin-specific sockets, add the following dependency:

<dependency>  <groupId>com.kohlschutter.junixsocket</groupId>  <artifactId>junixsocket-darwin</artifactId>  <version>2.10.1</version></dependency>

Custom architectures (usually not required)

See here how to add support for custom architectures that aren't supported out ofthe box.

Snapshot versions

If you're testing a-SNAPSHOT version, make sure that the Sonatype snapshot repository is enabledin your POM:

<repositories>    <repository>        <id>sonatype.snapshots</id>        <name>Sonatype snapshot repository</name>        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>        <layout>default</layout>        <snapshots>            <enabled>true</enabled>        </snapshots>    </repository></repositories>

Gradle

Add the following statements tobuild.gradle; if you have existing dependencies, append to thedependencies clause accordingly.

For the common Java code and common native libraries, add:

dependencies {    implementation 'com.kohlschutter.junixsocket:junixsocket-core:2.10.1'}

Some older Gradle versions requirecompile instead ofimplementation, and some older versions have trouble resolving thejunixsocket-core POM artifact. If you're running into problems (and only then), try the following:

dependencies {    implementation 'com.kohlschutter.junixsocket:junixsocket-common:2.10.1'    implementation 'com.kohlschutter.junixsocket:junixsocket-native-scommon:2.10.1'}

For RMI support, add:

    implementation 'com.kohlschutter.junixsocket:junixsocket-rmi:2.10.1'

For MySQL support, add:

    implementation 'com.kohlschutter.junixsocket:junixsocket-mysql:2.10.1'

For TIPC support, add:

    implementation 'com.kohlschutter.junixsocket:junixsocket-tipc:2.10.1'

For VSOCK support, add:

    implementation 'com.kohlschutter.junixsocket:junixsocket-vsock:2.10.1'

For Jetty support, add:

    implementation 'com.kohlschutter.junixsocket:junixsocket-jetty:2.10.1'

For SSL support, add:

    implementation 'com.kohlschutter.junixsocket:junixsocket-ssl:2.10.1'

(On Android, you may also want to addorg.bouncycastle:bcprov-jdk18on andorg.bouncycastle:bctls-jdk18on, since the default SSL implementation is incomplete)

For Darwin socket support, add:

    implementation 'com.kohlschutter.junixsocket:junixsocket-darwin:2.10.1'

Snapshot versions

Add the following “maven” line tosettings.gradle, or update accordingly:

dependencyResolutionManagement {    repositories {        mavenLocal()        mavenCentral()        repositories {            maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }        }    }}

jars only

If you don't use Maven or Gradle, etc., simply download the binary distribution from thejunixsocket releases page.

junixsocket-dist comes either as a.tar.gz or.zip archive. Get either one of them. The jarsare in thelib directory.

JDBC

junixsocket makes it easy to connect to a local database directly via Unix domain sockets.

There is a special implementation for MySQL, and a generic SocketFactory that can be used fordatabases such as PostgreSQL.

MySQL

If you can't use Maven (instructions above), make sure that the following jars are on your classpath:

  • junixsocket-common-2.10.1.jar
  • junixsocket-mysql-2.10.1.jar
  • mysql-connector-j-8.0.31.jar (or newer)
  • (typically required; can be skipped if you use the custom library below) junixsocket-native-common-2.10.1.jar
  • (optionally, if you have a custom architecture) junixsocket-native-custom-2.10.1.jar

Use the following connection properties (along withuser,password, and other properties you mayhave).

property namevalueremarks
socketFactoryorg.newsclub.net.mysql.AFUNIXDatabaseSocketFactory(1)
junixsocket.file/tmp/mysql.sock(2)
sslModeDISABLED(3)(4)

(1) This SocketFactory currently implements the “old” Connector/J SocketFactory interface.This may change in the future. For the time being, you can use a value oforg.newsclub.net.mysql.AFUNIXDatabaseSocketFactoryCJto forcibly use the new “CJ”-style SocketFactory.

(2) This is the full path to the MySQL socket. The location on your system may be different. Try/var/lib/mysql.sockif you can't find it in /tmp.

(3) This is optional, and forcibly disables the use of SSL. Since the connection is local, there'sno point in encrypting the communication. Disabling SSL may improve performance.

(4)sslMode is only available with mysql-connector-java 8.0.13 or newer. TryuseSSL with a value offalseto disable SSL with older versions of Connector/J.

PostgreSQL

Make sure that the following jars are on your classpath:

  • junixsocket-common-2.10.1.jar
  • postgresql-42.2.5.jar (or newer; earlier versions should work, too)
  • (typically, omit if you use the custom library below) junixsocket-native-common-2.10.1.jar
  • (optionally, if you have a custom architecture) junixsocket-native-custom-2.10.1.jar

Use the following connection properties (along withuser,password, and other properties you mayhave).

There are currently three distinct ways (socket factories) how to configure the connection to yourdatabase:

NOTE When specifying these class names from the command line, you may need to put them in singlequotes (or escape the$ sign), otherwise your shell may erroneously interpret$FactoryArg etc.as a variable and fail withjava.lang.ClassNotFoundException: org.newsclub.net.unix.AFUNIXSocketFactory

  1. org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg

    You provide the socket path via thesocketFactoryArg JDBC property.

    NOTE This is the recommended way for graphical database applications.

    The connection hostname must be set to “localhost”, any other value will not work.

    Connection URL:jdbc:postgresql://localhost/postgres

    property namevalueremarks
    socketFactoryorg.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg
    socketFactoryArg/tmp/.s.PGSQL.5432(1)
    sslmodedisable(2)
  2. org.newsclub.net.unix.AFUNIXSocketFactory$SystemProperty

    You provide the socket path via the system propertyorg.newsclub.net.unix.socket.default

    The connection hostname must be set to “localhost”, any other value will not work.

    Connection URL:jdbc:postgresql://localhost/postgres

    property namevalueremarks
    socketFactoryorg.newsclub.net.unix.AFUNIXSocketFactory$SystemProperty
    sslModedisable(2)
  3. org.newsclub.net.unix.AFUNIXSocketFactory$URIScheme

    You provide the socket path via the connection URL's hostname.

    The connection “hostname” can be specified as a file: URL (e.g.,file:///tmp/.s.PGSQL.5432).

    Since file URLs aren't valid hostnames and contain forward slashes, we have to encode themsomehow to pacify PostgreSQL's connection parser. This can be achieved using URL encoding:If the plain URL isfile:///tmp/.s.PGSQL.5432, then the URL-encoded version isfile%3A%2F%2F%2Ftmp%2F.s.PGSQL.5432.

    Performance trick: By placing a square bracket ([) in front of the host name, we canprevent any attempt to lookup the hostname in DNS. However, this is not mandatory.

    Connection URL:jdbc:postgresql://[file%3A%2F%2F%2Ftmp%2F.s.PGSQL.5432/postgres

    property namevalueremarks
    socketFactoryorg.newsclub.net.unix.AFUNIXSocketFactory$URIScheme
    sslModedisable(2)

Remarks

(1) This is the full path to the PostgreSQL socket. The location on your system may be different.Try/var/run/postgresql/.s.PGSQL.5432 if you can't find it in /tmp.

(2) This is optional, and forcibly disables the use of SSL. Since the connection is local, there'sno point in encrypting the communication. Disabling SSL may improve performance.

Specifying dependencies in third-party apps

DBeaver

DBeaver is an Open-Source universal database tool. To use junixsocket withDBeaver, for example to connect to PostgreSQL or MySQL databases, add junixsocket to thecorresponding driver settings.

DBeaver hasproblems with the POM-onlyjunixsocket-core artifact, so we have to specify bothjunixsocket-common andjunixsocket-native-common:

Select “Connect by URL” (not Host), then specify a JDBC URL from the variants above. Click “Driverproperties” and adjust the driver properties as instructed above.

In the “Connect to a database” dialog, click “Edit Driver Settings”. Under the “Libraries” tab,then add bothjunixsocket-common andjunixsocket-native-common dependencies via “Add Artifact”each; make sure to copy the full<dependency>...</dependency> XML fragment from theCommondependency section above. Afterwards, click “Download/Update” to ensure the drivers areaccessible.

Compatibility of future versions

We have documented someCompatibility Considerations, please keep themin mind before updating your dependencies.



[8]ページ先頭

©2009-2025 Movatter.jp