Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: com/google/crypto/tink/aead/AeadParameters #2

Open
manishjindal opened this issue May 24, 2024 · 3 comments
Assignees

Comments

@manishjindal
Copy link

Help us help you

We'd like to know more about
your Tink deployment.

Describe the bug:

I am trying to use the example https://github.com/tink-crypto/tink-java-gcpkms/blob/main/examples/envelopeaead/EnvelopeAeadExample.java but after adding all the dependencies it is showing following error:

Error: Unable to initialize main class org.example.EnvelopeAeadExample
Caused by: java.lang.NoClassDefFoundError: com/google/crypto/tink/aead/AeadParameters

What was the expected behavior?

It should run the example without any issues

How can we reproduce the bug?
Just compile and run the code and you should be able to reproduce this very easily.

Do you have any debugging information?

java -cp target/classes org.example.EnvelopeAeadExample                               
Error: Unable to initialize main class org.example.EnvelopeAeadExample
Caused by: java.lang.NoClassDefFoundError: com/google/crypto/tink/aead/AeadParameters

What version of Tink are you using?
1.13.0

Can you tell us more about your development environment?

java --version
openjdk 18.0.2.1 2022-08-18
OpenJDK Runtime Environment (build 18.0.2.1+1-1)
OpenJDK 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)

Is there anything else you'd like to add?

Provide any additional context about the problem.

@morambro
Copy link
Contributor

Hi manishjindal, how did you compile the example? Could you please provide the complete command you've used for javac with classpaths? Also please note that the class is envelopeaead.EnvelopeAeadExample

@manishjindal
Copy link
Author

Following is project structure:

├── pom.xml
├── src
│   └── main
│       └── java
│           └── envelopeaead
│               └── EnvelopeAeadExample.java
└── target
    ├── classes
    │   └── envelopeaead
    │       └── EnvelopeAeadExample.class
    ├── encrypt-file-1.0-SNAPSHOT.jar
    ├── generated-sources
    │   └── annotations
    ├── maven-archiver
    │   └── pom.properties
    └── maven-status
        └── maven-compiler-plugin
            └── compile
                └── default-compile
                    ├── createdFiles.lst
                    └── inputFiles.lst

and following are the content of my pom.xml file:

<?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>your-group-id</groupId>
    <artifactId>encrypt-file</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>11</java.version>
    </properties>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.39.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-kms</artifactId>
  </dependency>

 <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-storage</artifactId>
        </dependency>
  <dependency>
  <groupId>com.google.crypto.tink</groupId>
  <artifactId>tink</artifactId>
  <version>LATEST</version>
</dependency>

<dependency>
  <groupId>com.google.crypto.tink</groupId>
  <artifactId>tink-gcpkms</artifactId>
  <version>LATEST</version>
</dependency>

    </dependencies>

        <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And I am using following command to compile the code:

mvn clean install

And using following command to run :

java -cp target/classes envelopeaead.EnvelopeAeadExample
Error: Unable to initialize main class envelopeaead.EnvelopeAeadExample
Caused by: java.lang.NoClassDefFoundError: com/google/crypto/tink/aead/AeadParameters

@morambro
Copy link
Contributor

I think you should use mvn exec:java to run the example given that the dependencies are handled with Maven. I'd recommend trying something like this.

@morambro morambro self-assigned this May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants