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

JavaJvmJava 9javax.activation

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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" />

Solution 2 - Java

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.

Solution 3 - Java

Update 2020

the next renaiming

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

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

(The package names within this libraries is 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.2</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 this 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>

Solution 4 - Java

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>

Solution 5 - Java

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.

Solution 6 - Java

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

compile 'javax.mail:mail:1.4.7'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDmitriy DumanskiyView Question on Stackoverflow
Solution 1 - JavaNamanView Answer on Stackoverflow
Solution 2 - JavaAlan BatemanView Answer on Stackoverflow
Solution 3 - JavaRalphView Answer on Stackoverflow
Solution 4 - JavaMichal CzView Answer on Stackoverflow
Solution 5 - JavaBenjamín ValeroView Answer on Stackoverflow
Solution 6 - Javaasifaftab87View Answer on Stackoverflow