pipeline {
    agent any
    tools {
        maven 'MVN-WSL'
    }

    stages {
        stage('Maven Build (WAR)') {
            steps {
                dir('proiect-nutritie-java') {
                    sh 'mvn clean package'
                }
            }
        }

        stage('Docker Build & Deploy (Tomcat)') {
            steps {
                dir('proiect-nutritie-java') {
                    sh 'docker build -t nutritie-java-war .'
                    
                    sh '''
                    docker stop container-java || true
                    docker rm container-java || true
                    docker run -d -p 8086:8080 --name container-java nutritie-java-war
                    '''
                }
            }
        }
    }
}