What is the replacement for javax.activation package in java 9?

122.5k Views Asked by At

Seems like javax.activation package is deprecated in Java 9. Oracle migration guide proposes to use --add-modules java.activation option during JVM start.

However, I would like to avoid this and replace javax.activation package's classes, as it is deprecated and will be removed in future java versions. I suppose, there should be some kind of alternative for javax.activation. If there is any available, what is it?

6

There are 6 best solutions below

1
Naman On BEST ANSWER

JavaBeans Activation Framework (JAF) is possibly the alternative you are looking for to the existing package.

This standalone release of JAF uses a Java Platform Module System automatic module name of java.activation, to match the module name used in JDK 9. A future version will include full module metadata.

The standalone APIs are supported in modular form only, via the concept of upgradeable modules. Using them, it's possible to use a version of that module from a later release in any phase, i.e., at compile time, build time, or runtime.


The currently available version for this is 1.2.0 which can be used like this:

Maven

<dependency>
    <groupId>com.sun.activation</groupId>
    <artifactId>javax.activation</artifactId>
    <version>1.2.0</version>
</dependency>

Gradle

compile 'com.sun.activation:javax.activation:1.2.0'

Ivy

<dependency org="com.sun.activation" name="javax.activation" rev="1.2.0" />
2
Alan Bateman On

The JavaBeans Activiation Framework is a standalone technology with its own maintenance JSR in the JCP and its own download. Yes, Java SE 9 has deprecated it and has proposes to remove in a future release along with the modules shared with Java EE but this doesn't impact the standalone version. The standalone version will live on. If you are using Maven then this should work:

<dependency>
  <groupId>com.sun.activation</groupId>
  <artifactId>javax.activation</artifactId>
  <version>1.2.0</version>
</dependency>

and if you are developing a module then you can use requires java.activation.

0
Michal Cz On

As written above, java versions > 8 are not providing javax.activation. I met this exception when working on camel project. I've just added the following dependency:

<!-- https://mvnrepository.com/artifact/javax.activation/activation -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
0
Benjamín Valero On

I am using module configuration in my project, so this issue has been simply solved by adding requires java.activation to the module-info.java file.

2
Ralph On

Update 2020

the next renaming

(due to some legal issues, javax.* was renamed to jakarta.*. So the current 1.2.2+ versions of Jakarta Activation Framework use the names:

  • jakarta.activation:jakarta.activation-api (instead of javax.activation:javax.activation-api) or
  • com.sun.activation:jakarta.activation (instead of com.sun.activation:javax.activation and javax.activation:activation)

(The package names within these libraries are still javax.activation so this issue is just with the Maven dependency names)

<dependency>
    <groupId>jakarta.activation</groupId>
    <artifactId>jakarta.activation-api</artifactId>
    <version>1.2.2</version>
</dependency>

or

<dependency>
    <groupId>com.sun.activation</groupId>
    <artifactId>javax.activation</artifactId>
    <version>1.2.0</version>
</dependency>

Attention: you do not need both dependencies, because com.sun.activation:javax.activation include the classes from jakarta.activation:jakarta.activation-api


Hint Use Maven enforcer to keep your project free of these duplicates:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.0.0-M3</version>
    <executions>
        <execution>
            <id>enforce-lib-ban</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <bannedDependencies>
                        <!-- the activation framework was renamed to jarkata activation framework -->
                        <excludes>
                            <exclude>javax.activation:javax.actication-api</exclude>                        
                            <exclude>com.sun.activation:javax.activation</exclude>
                            <exclude>javax.activation:activation</exclude>
                        </excludes>
                        <message>use jakarta.activation:jakarta.activation-api or com.sun.activation:jakarta.activation instead of javax.activation</message>
                    </bannedDependencies>
<!-- if you use com.sun.activation:jakarta.activation
                    <bannedDependencies>
                        <!- - the implementation com.sun.activation:jakarta.activation contains the api classes too - ->
                        <excludes>
                            <exclude>jakarta.activation:jakarta.activation-api</exclude>
                        </excludes>
                        <message>the implementation com.sun.activation:jakarta.activation is included and it contains the api classes too</message>
                    </bannedDependencies>
-->
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>
0
asifaftab87 On

I have to send mail in Liferay 7.1 so I added dependency like this

compile 'javax.mail:mail:1.4.7'