84

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?

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
Dmitriy Dumanskiy
  • 11,657
  • 9
  • 37
  • 57
  • 7
    A small addition: JDK 11 actually removes this (as part of JEP 320), so starting with that JAF has to be included as a separate dependency if used. – blalasaadri Nov 19 '18 at 18:22
  • what is javax activation dependency for mail required? javax.mail should suffice. Right? – Satish Patro Apr 16 '20 at 07:15
  • 4
    javax.mail's MimeBodyPart uses activation's DataHandler to set the mime content for that part. I ran into that today. Couldn't figure out why the main thread simply vanished on me while running in the IDE even. I was only catch Exception, so the class not found thing slipped right through. After telling my project should run using JRE 8, the problem went away> Lost hours on this. – Mike Nov 11 '20 at 04:37

6 Answers6

84

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" />
Jonathan
  • 6,741
  • 7
  • 52
  • 69
Naman
  • 27,789
  • 26
  • 218
  • 353
  • 19
    Eclipse foundation has [taken over JavaEE development](https://www.eclipse.org/ee4j/faq.php). `javax.activation` has moved to `jakarta.activation` per https://wiki.eclipse.org/New_Maven_Coordinates – Gili Jan 30 '19 at 18:01
29

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
Alan Bateman
  • 5,283
  • 1
  • 20
  • 25
  • So with `javaee-api` dependency with scope=provided I have to add this one? – Dmitriy Dumanskiy Sep 29 '17 at 17:23
  • 3
    Now with JakartaEE, the sources are hosted by the Eclipse foundation and could be found on GitHub: https://github.com/eclipse-ee4j/jaf and on Maven central: https://mvnrepository.com/artifact/com.sun.activation/jakarta.activation With that the `artifactId` changed to `jakarta.activation` and the version number to `1.2.1` – jonashackt Aug 30 '19 at 11:44
23

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 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.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 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>
CloudWatcher
  • 181
  • 1
  • 11
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • This worked for me. I had to install Eclipse fresh (work from home) to work on a legacy project, and the latest Eclipse (20210910-1417) has its own JDK that can compile Java 8, but does not include the original javax.activation jar file, as noted. I needed Mime in the mail package, and jakarta.activation-1.2.1.jar allowed the project to get compiled. – JasonH Sep 23 '21 at 16:16
  • There is **no** such dependency::: `- com.sun.activation javax.activation 1.2.2` - changed the version to 1.2.0 – Lonzak Apr 24 '23 at 14:36
2

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>
Michal Cz
  • 21
  • 1
2

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.

0

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

compile 'javax.mail:mail:1.4.7'

asifaftab87
  • 1,315
  • 24
  • 28