2

I'm using embedded tomcat in my spring boot application. I tun application with goal below:

clean spring-boot:run

and it runs with no error. I use eclipse shutdown button to shut it down. second time i try to run it i get this :

Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project cpanel: Failed to clean project: Failed to delete XXXXXXXXX\target\classes\hibernate\security\user\User.hbm.xml -> [Help 1]

it sims tomcat can't delete target for next time. whats wrong with my tomcat? Am i doing some thing wrong?

My server configuration in application.yml:

server:
compression:
    enabled: true
port: 8080
servlet-path: /rest

and my tomcat dependency:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>
Hadi Rasouli
  • 1,871
  • 3
  • 27
  • 43
  • I suspect that `spring-boot:run` has forked a second JVM and Eclipse doesn't shut them both down correctly. I'd take Maven out of the picture completely by running your main class directly in Eclipse rather than running it via Eclipse's Maven integration. – Andy Wilkinson May 17 '16 at 12:20

3 Answers3

3

To solve this problem, change tomcat maven plugin and add fork to false

   <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <fork>false</fork>
        </configuration>
  </plugin>
Hadi Rasouli
  • 1,871
  • 3
  • 27
  • 43
ali akbar azizkhani
  • 2,213
  • 5
  • 31
  • 48
  • Although this worked by not forking, I ran into other dependency conflicts. I just right clicked on my main class and `Run As > Java App`. When you stop, tomcat stops. – code4kix Jun 08 '18 at 19:14
1

I wrote this bat script command:

FOR /F "tokens=5 delims= " %%P IN ('netstat -a -n -o ^| findstr :8080.*LISTENING') DO TaskKill.exe /PID %%P /F pause and saved it in killport.bat, then called it with maven-antrun-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>compile</phase>
            <configuration>
                <target>
                    <exec executable="cmd.exe" spawn="true">
                        <arg value="/c" />
                        <arg value="F:\Java\Projects\killport.bat" />
                    </exec>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71
0

Just add the following Tag in to the spring-boot-maven-plugin in the pom.xml file

            <configuration>
                <fork>false</fork>
            </configuration>

here is the full Example :

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <fork>false</fork>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>