jeudi 15 octobre 2015

Maven cannot find java.util.Objects when using mvn shade plugin?

I'm following AWS lambda's "create a jar using mvn":

http://ift.tt/1METsk0

and some reason when I try to do either "mvn clean install" nor "mvn package" run properly. the project is using java 8.

Here's my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://ift.tt/IH78KX"
         xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/VE5zRx">
    <modelVersion>4.0.0</modelVersion>

    <groupId>lambda</groupId>
    <artifactId>test</artifactId>
    <packaging>jar</packaging>
    <version>0.0.0.1-SNAPSHOT</version>
    <name>lambda-test</name>

    <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-core</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-events</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.53</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

and my code:

package lambda.test;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.google.gson.Gson;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

import java.util.Objects;
import java.util.Properties;
import java.util.Vector;

public class Test {

    private static final Gson gson = new Gson();

    public static String myHandler(Tester tester, Context context) {
        LambdaLogger logger = context.getLogger();
        logger.log("received: " + tester);

        try {
            JSch jSch = new JSch();
            Session session = jSch.getSession(username, sftpHost, sftpPort);
            session.setPassword(password);

            Properties config = new Properties();
            config.put("StrictHostKeyChecking", "no");

            session.setConfig(config);
            session.connect(15000);

            ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
            channel.connect();

            channel.cd("Inbox");
            Vector<ChannelSftp.LsEntry> list = channel.ls(".");

            logger.log("the list ==> \n" + gson.toJson(list));
        } catch (Exception e) {
            e.printStackTrace();
            logger.log("the exception: " + e.getMessage());
        }

        return String.valueOf(tester);
    }

    public static class Tester {
        private final String name;
        private final Integer id;

        public Tester(String name, Integer id) {
            this.name = name;
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public Integer getId() {
            return id;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Tester tester = (Tester) o;
            return  Objects.equals(name, tester.name) &&
                    Objects.equals(id, tester.id);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name, id);
        }

        @Override
        public String toString() {
            return gson.toJson(this);
        }
    }
}




1 commentaire: