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

[native-image] how to compile with jar dependencies? ("Main entry point class not found") #1939

Closed
jgranduel opened this issue Dec 5, 2019 · 4 comments

Comments

@jgranduel
Copy link

Hi,

sorry if this is written somewhere, but I have not been able to compile a simple program with dependencies.,
My env is Win10x64, graalvm-19.3.0 as described in #1886 .

native-image.cmd -cp ".;./dependency.jar" MyCls
[A:31264]    classlist:   1,690.56 ms
Error: Main entry point class './dependency.jar' not found.
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

//tried with my own test lib and with [vavr](https://www.vavr.io/) for instance
>javac -cp ".;./vavr-1.0.0-alpha-3.jar" C.java
> java -cp ".;./vavr-1.0.0-alpha-3.jar" C
....OK

>native-image.cmd -cp ".;./vavr-1.0.0-alpha-3.jar" C
[C:43276]    classlist:   1,675.54 ms
Error: Main entry point class './vavr-1.0.0-alpha-3.jar' not found.
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

>native-image.cmd -cp ".;./vavr-1.0.0-alpha-3.jar" C "-H:+ReportExceptionStackTraces"
[C:42452]    classlist:   1,644.75 ms
Error: Main entry point class './vavr-1.0.0-alpha-3.jar' not found.
com.oracle.svm.core.util.UserError$UserException: Main entry point class './vavr-1.0.0-alpha-3.jar' not found.
at com.oracle.svm.core.util.UserError.abort(UserError.java:65)
at com.oracle.svm.hosted.NativeImageGeneratorRunner
          .buildImage(NativeImageGeneratorRunner.java:262)
 at com.oracle.svm.hosted.NativeImageGeneratorRunner
          .build(NativeImageGeneratorRunner.java:454)
at com.oracle.svm.hosted.NativeImageGeneratorRunner
          .main(NativeImageGeneratorRunner.java:115)
at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus
          .main(NativeImageGeneratorRunner.java:479)
Error: Image build request failed with exit status 1

But it might not be the way to do it? I tried with a command taken in graalvm doc $GRAALVM_HOME/bin/native-image -cp ./target/mixed-code-hello-world-1.0-SNAPSHOT.jar -H:Name=helloworld -H:Class=hello.JavaHello -H:+ReportUnsupportedElementsAtRuntime --allow-incomplete-classpath . I also tried to build a jar, but again I got the entry point issue.

Thanks in advance (and for completing the documentation if needed).
Best regards

@jgranduel
Copy link
Author

I have been able to compile the code into exe by dumbly unzipping the dependency and then rebuilding a jar with the dependency inside.

> jar xvf dependency.jar
> jar cfe my.jar Main ./Main.class dependencyFolder
> native-image.cmd -jar my.jar
> ./my.exe

So, the dependency is not the cause. Is this process already included in native-image.cmd when using -cp as of graalvm-19.3.0 ?
Thanks

@ghost
Copy link

ghost commented Dec 25, 2019

@jgranduel,
I tried your example and it works well in cmd and in "x64 Native Tools Command Prompt for VS 2017" (the same cmd).
Here is a code of Hello.java:

import io.vavr.control.Try;

public class Hello {
    public static void main(String[] args) {
        int x = 10;
        int y = 0;
        int defaultValue = 5;
        Integer result = Try.of(() -> (x / y))
                .getOrElse(defaultValue);
        System.out.println(result);
    }
}

And the commands:

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.18
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>D:

D:\>cd dev\projects\vavr-example

D:\dev\projects\vavr-example>set JAVA_HOME=D:\dev\sdk\graalvm-ce-java11-19.3.0

D:\dev\projects\vavr-example>%JAVA_HOME%\bin\javac -cp vavr-0.10.2.jar Hello.java

D:\dev\projects\vavr-example>%JAVA_HOME%\bin\java -cp .;vavr-0.10.2.jar Hello
5

D:\dev\projects\vavr-example>%JAVA_HOME%\bin\native-image -cp ".;vavr-0.10.2.jar" Hello
[hello:2872]    classlist:   1,104.46 ms
[hello:2872]        (cap):   2,730.45 ms
[hello:2872]        setup:   3,752.05 ms
[hello:2872]   (typeflow):   3,755.56 ms
[hello:2872]    (objects):   3,500.41 ms
[hello:2872]   (features):     164.81 ms
[hello:2872]     analysis:   7,585.20 ms
[hello:2872]     (clinit):     105.90 ms
[hello:2872]     universe:     322.53 ms
[hello:2872]      (parse):     424.18 ms
[hello:2872]     (inline):   1,147.42 ms
[hello:2872]    (compile):   3,528.94 ms
[hello:2872]      compile:   5,401.95 ms
[hello:2872]        image:     533.08 ms
[hello:2872]        write:     519.57 ms
[hello:2872]      [total]:  19,383.30 ms

D:\dev\projects\vavr-example>hello.exe
5

@jgranduel
Copy link
Author

@jbreathe
Thank you very much for taking the time to test on Windows. I thought I had understood how to set the environment in PowerShell, but not fully yet. The message about the "Entry Point" was misleading for me. I haven't been able to compile your code without switching to cmd.exe and running C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsMSBuildCmd.bat (VS 2019) from there. Still frustrating from PowerShell but happy to compile the basic example. I can speak about GraalVM aound. Cheers.

@pejovica
Copy link
Member

Closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants