Error: Invalid or corrupt jarfile /app.jar - spring

Help, I'm trying to upload the spring boot application to fly.io
2022-12-27T18:13:45Z [info]Preparing to run: `java -jar /app.jar` as root
2022-12-27T18:13:45Z [info]2022/12/27 18:13:45 listening on [fdaa:1:12ef:a7b:a0:3feb:41aa:2]:22 (DNS: [fdaa::3]:53)
2022-12-27T18:13:45Z [info]Error: Invalid or corrupt jarfile /app.jar
2022-12-27T18:13:46Z [info]Starting clean up.
--> v45 failed - Failed due to unhealthy allocations - not rolling back to stable job version 45 as current job has same specification and deploying as v46
--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort
FROM ibm-semeru-runtimes:open-17-jre-focal
EXPOSE 8080
ARG JAR_FILE= ./target/*.jar
COPY ${JAR_FILE} /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.tasf</groupId>
<artifactId>prueba</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>prueba</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
buid
BUILD SUCCESS
Total time: 10.109 s
Finished at: 2022-12-27T13:20:04-05:00
he requested profile "pom.xml" could not be activated because it does not exist.

the .dockerignore file was ignoring the /target path

Related

Compile project that references installed project

I have a library module that I created through Maven, there is pom.xml what get dependencies:
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.18.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.library</groupId>
<artifactId>commons</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>commons</name>
<description>common dependencies library</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
With the above pom, I successfully installed it into the local maven repository by using mvn install.
In another project my-service, which uses this installed library, within the IntelliJ IDEA, it is fine compiling and running. There is the pom.xml for the my-service
<?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>com.example</groupId>
<artifactId>my-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-service</name>
<description>My Services</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.18.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- other dependencies ... -->
<dependency>
<groupId>com.example.library</groupId>
<artifactId>commons</artifactId>
<version>1.0.0</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
However, when running with mvn compile, I got the following errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-service: Compilation failure: Compilation failure:
[ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[3,45] package com.example.library.commons.filters does not exist
[ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[17,13] cannot find symbol
[ERROR] symbol: class SessionFilter
[ERROR] location: class com.example.myservice.configs.WebSecurityConfig
[ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[19,36] cannot find symbol
[ERROR] symbol: class SessionFilter
[ERROR] location: class com.example.myservice.configs.WebSecurityConfig
The library project is created as part of the IntelliJ IDEA module within the same project as the my-service module. I guess the IntelliJ IDEA knows how to internally references module to compile the depending modules, but with Maven, it is a different story.
My goal is to compile and package the my-service module as a single jar that includes the commons library module. Now I can't even get it to compile with Maven, what did I do wrong?
Apache Maven version 3.3.9 . Operating system: OS X.
It turns out the Spring-boot-maven plugin is not needed in the library project because a library doesn't need to produce an executable ueber jar. After removing the plugin, it compiles successfully.

Fabric8 Docker Maven plugin not working for compose.yml on Multi module project

I trying to use Fabric8 docker-maven-plugin, though I was successful in configuring plugin for individual module and run docker:build docker:start Maven goal without using docker-compose.yml, however I needed externalize ports and link the different module, hence I intended to use docker-compose.yml. Below is my project structure.
--kp-parent
|
--- docker-compose.yml
--- pom.xml
|
---- rest1
| |
| -- .maven-dockerignore
| -- pom.xml
| -- Dockerfile
---- rest2
| |
| -- .maven-dockerignore
| -- pom.xml
| -- Dockerfile
Here are my configurations
Dockerfile[both rest1 and rest2 use identical file except the different port]
FROM openjdk:8-jdk-alpine
MAINTAINER 'Karthik Prasad'
ARG IMAGE_VERSION
ARG JAR_FILE
ENV JAVA_OPTS=""
LABEL version = IMAGE_VERSION
VOLUME /tmp
ADD /maven/${JAR_FILE}.jar app.jar
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
EXPOSE 8000
.maven-dockerignore[In both child modules identical file]
target/**
pom.xml [Both rest1 and rest2 pom files are same except the artifcatid and name of the project]
<?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>
<artifactId>rest2</artifactId>
<packaging>jar</packaging>
<name>rest2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.kp.swasthik</groupId>
<artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- https://mvnrepository.com/artifact/io.fabric8/docker-maven-plugin -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<images>
<image>
<external>
<type>compose</type>
<basedir>../</basedir>
<ignoreBuild>true</ignoreBuild>
</external>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>
parent pom.xml
<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>com.kp.swasthik</groupId>
<artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>kp-docker-multimodule-fabric8-parent</name>
<description>Microservice Parent Pom file</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<modules>
<module>rest1</module>
<module>rest2</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<docker.image.prefix>kp-ms</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.22.1</version>
<configuration>
<skip>true</skip>
<images>
<image>
<alias>${project.artifactId}</alias>
<name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
<build>
<dockerFileDir>${project.basedir}</dockerFileDir>
<assembly>
<inline>
<id>default</id>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</inline>
</assembly>
</build>
</image>
</images>
<buildArgs>
<IMAGE_VERSION>${project.version}</IMAGE_VERSION>
<JAR_FILE>${project.artifactId}-${project.version}</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
And finally docker-compose.yml
version: '2'
services:
rest1:
image: kp-ms/rest1:0.0.1-SNAPSHOT
ports:
- 8000:8000
rest2:
image: kp-ms/rest2:0.0.1-SNAPSHOT
ports:
- 8001:8001
links:
- rest1
When I run the docker:build docker:start I get below error.
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.22.1:start (default-cli) on project rest1: I/O Error: Unable to pull 'kp-ms/rest2:0.0.1-SNAPSHOT' : repository kp-ms/rest2 not found: does not exist or no pull access (Not Found: 404) -> [Help 1]
[ERROR]
However If I remove rest2 section in docker-compose.yml, build goes fine and I'm able to find the container start successfully.
Another problem I noticed is that even if do not give image name in docker-compose.yml build fails with error image is null. However I'm not sure why I need to provide image can't the plugin map from plugin configuration as I had provided alias. As you can notice I'm trying to generate image name dynamically.

spring boot multi modules package

I am trying to use Maven to package Spring Boot with multi modules,Here my main module pom.xml :
<modules>
<module>my-data-services</module>
<module>my-message-services</module>
<module>my-common</module>
</modules>
<groupId>com.my</groupId>
<artifactId>my-multi-services</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>....</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
my-common pom.xml:
<parent>
<artifactId>my-multi-services</artifactId>
<groupId>com.my</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-common</artifactId>
<packaging>jar</packaging>
<dependencies>....</dependencies>
and my-data-services pom.xml:
<parent>
<artifactId>my-multi-services</artifactId>
<groupId>com.my</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-data-services</artifactId>
<dependencies>
<dependency>
<groupId>com.my</groupId>
<artifactId>my-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
my-common module is just a common utils lib not a runnable module,but when i trying to mvn clean package,exception throws below:
Execution default of goal org.springframework.boot:spring-boot-maven-p
lugin:1.4.2.RELEASE:repackage failed: Unable to find main class
then i add a main class,this module can package,but its not a lib jar, its like a runnable spring boot jar
-BOOT-INF
|
-META-INF
|
-org
and the exception throws
Failed to execute goal org.apache.maven.plugins:maven-compiler- plugin:3.1:compile (default-compile) on project my-data-services: Compilation failure: Compilation failure: package com.my.common.utils does not exist;
com.my.common.utils is in module my-common
How do i fix this problem, and in spring boot multi modules project,how to package a common utils lib without BOOT-INF
This happens because your modules will have the 'spring-boot-maven-plugin' added to them because it's defined in their parent.
What you need to do is move everything into submodules, even your application starter class. How I do this usually:
my-parent-module
my-service-module
my-common-module
my-web-module (or my-runtime-module in a non-web app)
The my-parent-module will have 'spring-boot-starter-parent' as it's parent but it not going to have an src folder because everything is moved into submodules.
The my-web-module will depend on the other modules and will have the 'spring-boot-maven-plugin'. You will be able to run the app with 'mvn spring-boot:run' in the my-web-module folder.

Error when opening a new Spring Boot Project using SpringToolSuite

I am new to Spring.I downloaded SpringToolSuite 3.7.2 and i am trying to create a simple SpringBootApplication.
I go to File->New Spring Starter Project,Select Type as Maven project and Under dependencies i selected Web and click on Finish. I get an error on my parent tag in pom.xml and also not able to see the maven dependency libraries.
I tried right clicking on the project->Select Maven->Update Projects-> Checked all boxes and Update but does not work. I also tried cleaning the repository under C:{User}.m2 clean and rebuild the project but did not work for me.Screenshot of the STS
Project build error: Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.4.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org and 'parent.relativePath' points at no local POM
Please tell me what am i missing.
Below is my pom.xml
<?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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringApplication1</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The error suggests that you are not able to connect to (https://repo.maven.apache.org/maven2).
Please check your maven settings.xml (Window -> Preferences -> Maven -> Global/User Settings):
If you are using proxy, you need to add it on your settings.xml.
Something like this :
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<proxies>
<proxy>
<id>myproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
</proxy>
</proxies>
...
</settings>
As you can see on https://maven.apache.org/settings.html.
If you are not using proxy, be sure that you don't have any proxy configuration on your settings.

maven copy plugin for spring-boot

I have created a Spring Boot application where I have few Javascript & Html files in the path src/main/resources/public/app.
My project folder structure is :
/project
-/src/main
-- /java
-- / resources
--- /application.properties
--- /public
---- /app
----- /index.html
----- /bower-components
----- /scripts
----- /views/**.html
----- /images
----- /styles
----/dist
-----/index.html
-----/vendor.ZXASF.js
-----/scripts.QASD.js
When I run the Javascript minification task, I generate a dist [distribution] folder as shown above. Now my requirement is, I want to tell maven which folder to include in the JAR file when mvn clean install is run. If I run in "DEBUG" mode, the folder src/main/resources/app folder needs to included in the JAR file. When I run in "DEPLOY" mode, the src/main/resources/dist folder needs to be included. Please note, the path of these folders in the JAR file should be as per the project folder structure. I tried with several options but no luck till now. My pm.xml is as below:
<?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>spring-boot-demo</groupId>
<artifactId>spring-boot-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.SpringBootDemoApplication</start-class>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Thanks

Resources