4

I am getting the below error when I tried to use HTTPS in spring native application.

java.net.MalformedURLException: Accessing an URL protocol that was not enabled. The URL protocol HTTPS is supported but not enabled by default. It must be enabled by adding the --enable-url-protocols=https option to the native-image command.

HTTPS URL protocol was not enabled. Please help me to enable during the build.

Update

Found the solution, looking on spring native documentation. https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-image-options

Add the below code to pom.xml under the plugin section

<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>--enable-https</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>

Updated pom.xml looks like this.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <builder>paketobuildpacks/builder:tiny</builder>
            <env>
                <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>--enable-https</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
            </env>
        </image>
    </configuration>
</plugin>
zeeshan ansari
  • 381
  • 3
  • 16
  • 2
    Please don't answer your question in the question. Instead answer it in an actual answer and after a few days accept it, if it is still the best answer. This way others find the answer easier, and can easily see the question is answered. Also you might get upvotes for the answer. – Jens Schauder Mar 24 '21 at 06:58

2 Answers2

2

or if you using graalvm native image plugin:

                     <plugin>
                        <groupId>org.graalvm.nativeimage</groupId>
                        <artifactId>native-image-maven-plugin</artifactId>
                        <version>21.0.0</version>
                        <configuration>
                            <!-- The native image build needs to know the entry point to your application -->
                            <mainClass>com.dccorp.nativeapps.NativeCloudStreamsApplication</mainClass>
                            <buildArgs>
                                <!-- uncomment to generate dump file for graalvm dashboard analysis.-->
                                <!-- -H:DashboardDump=dumpfileoversizedbuildArgs-->
                                <!-- -H:+DashboardAll-->
                                <!-- you can provide additional params. -->
                                <!-- -H:DynamicProxyConfigurationFiles=classes/proxy-config.json-->
                                <!-- -H:ReflectionConfigurationFiles=classes/reflect-config.json-->
                                --enable-url-protocols=http
                            </buildArgs>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>native-image</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                        </executions>
                    </plugin>
Deepak Chaudhary
  • 152
  • 1
  • 11
-1

Open up your configurations file and add the following line to that file and I hope it will work, as it has been mentioned in the error as well.

--enable-url-protocols=https
  • Can you please help me where I can find onfigurations file? Folder structure as this. https://drive.google.com/file/d/1Ty1FnZh8HxnQU2fJDNSD3ESDKY1xw75l/view?usp=sharing – zeeshan ansari Mar 20 '21 at 05:25
  • When you create a new Spring Boot Project, you have to create a new application.properties file by yourself. After creating that application.properties file you have to mention some properties that you will be using in the application. For better understanding have a look at the below mentioned post. https://www.javatpoint.com/spring-boot-properties – Abdur Rehman Khalid Mar 20 '21 at 07:39