Niente da fare non riesco a cavare il ragno dal buco…
Ho un progetto 1 in Spring Boot su IntelliJ che funziona alla perfezione ed un progetto 2 in Docker che funziona alla perfezione. Il progetto 1 funziona perché in locale viene renderizzato perfettamente nel browser. Il progetto 2 funziona alla perfezione perché se provo ad usarlo con un .jar di un’altra WebApp in Spring Boot non fa una piega.
Io penso ad un’errata scrittura del file pom.xml, dei file properties oppure ad una errata configurazione dell’IDE (quest’ultima meno probabile).
Sono giorni che sto smanetto e non so più dove sbattere la testa.
In pratica sul terminale di Linux (per testare il progetto 2 uso una VM Linux di vmware) ottengo questo errore:
no main manifest attribute, in /demoapp/Nomefilejar-9.0.jar
Il file .jar che ottengo è anche troppo piccolo,
solo 5MB, ma dovrebbe essere come minimo di 20MB.
PROGETTO 2
FROM openjdk:11.0.15-jre-slim
EXPOSE 8080
EXPOSE 8433
WORKDIR /demoapp
COPY jarfile/Nomefilejar-9.0.jar /demoapp/
CMD ["java", "-jar", "/demoapp/Nomefilejar-9.0.jar"]
PROGETTO 1
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.0</version>
<relativePath/>
</parent>
<groupId>it.applicazionijava</groupId>
<artifactId>gestioneutenti</artifactId>
<version>9.0</version>
<packaging>jar</packaging>
<name>gestioneutenti</name>
<description>WebApp con Spring Boot, Security, Thymeleaf e PostgreSQL</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--/* <scope>provided</scope> */-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.1</version>
</dependency>
</dependencies>
<build>
<finalName>Nomefilejar-${project.version}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--/*
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
*/-->
<!--/*
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>
WEB-INF/classes/it/applicazionijava/${project.name}/CrittografarePassword.class,
WEB-INF/classes/application-sviluppo.properties,
WEB-INF/classes/KeyStore.jks,
WEB-INF/classes/drop.sql
</packagingExcludes>
</configuration>
</plugin>
*/-->
</plugins>
</pluginManagement>
</build>
</project>
application-sviluppo.properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/...
spring.datasource.username=...
spring.datasource.password=...
spring.sql.init.schema-locations = classpath:drop.sql, classpath:schema.sql
server.port=8443
server.address=127.0.0.1
server.ssl.key-store=classpath:KeyStore.jks
server.ssl.key-store-password=mysecret
server.ssl.keyStoreType=JKS
server.ssl.keyAlias=mydomain
logging.level.org.springframework=INFO
spring.sql.init.mode=always
spring.sql.init.continue-on-error=false
application.properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=...
spring.datasource.username=...
spring.datasource.password=...
server.port=8443
server.ssl.key-store=...
server.ssl.key-store-password=...
server.ssl.keyStoreType=...
server.ssl.keyAlias=...
logging.level.org.springframework=INFO
spring.sql.init.mode=always
spring.sql.init.continue-on-error=false
application-docker.properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://postgresql-postgis:5432/...
spring.datasource.username=...
spring.datasource.password=...
spring.sql.init.schema-locations = classpath:schema.sql
server.port=8443
server.address=postgresql-postgis
server.ssl.key-store=classpath:KeyStore.jks
server.ssl.key-store-password=mysecret
server.ssl.keyStoreType=JKS
server.ssl.keyAlias=mydomain
logging.level.org.springframework=INFO
spring.sql.init.mode=always
spring.sql.init.continue-on-error=false
MANIFEST.MF (aggiunto dall'IDE)
Manifest-Version: 1.0
Main-Class: it.applicazionijava.gestioneutenti.GestioneUtentiApplication
GestioneUtentiApplication.java
package it.applicazionijava.gestioneutenti;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Profile;
@SpringBootApplication
@Profile("docker")
public class GestioneUtentiApplication extends SpringBootServletInitializer {
//@Override
//protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// return application.sources(GestioneUtentiApplication.class);
//}
public static void main(String[] args) {
System.setProperty("server.servlet.context-path", "/it");
SpringApplication.run(GestioneUtentiApplication.class, args);
}
}
ConfigurazioneTomcatConHttps.java
package it.applicazionijava.gestioneutenti.autenticazione_spring_security;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ConfigurazioneTomcatConHttps {
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}
}
Configurazione IntelliJ Idea