1

I am using Eclipse and I don't have Tomcat registered in Server view (please don't say me to add new server).

I started the debug mode in Eclipse by doing two settup in Debug Configurations

1 - enter "clean install tomcat7:run-war -Dspring.profiles.active=development" in Goals under Main tab

2 - and added the project in Source tab.

The Tomcat starts and I can debug perfectly the java code. The problem is, whenever I change a small thing in java or html, if I don't stop and start again via "clean install tomcat7:run-war -Dspring.profiles.active=development" it will not take effect at all. You can imagine I am losing time.

I read somewhere that I can copy and paste the html and class edited files straight in target directory but target/tomcat only contains conf and log folders. In target I do see my_app.war. Btw, it must exist a better way to make the changed code be refreshed by Tomcat.

The straight question is: How to make the changes in my source be automatically re-publish to Embedded Tomcat when starting the debug with tomcat7:run-war?

I saw several forum topics teaching how to do it with a server registered in Eclipse but my case is a bit different.

I guess, but I have no idea what, I am doing something wrong here "installsources..."

The closest topic I have found is

How to run tomcat7-maven-plugin, that server code changes will be updated immediately

In this question, basically, I found two suggestions:

1 - Turn off the test scripts (well, it is still necessary to re-start the embedded server although a bit faster in some scenarios)

2 - Use "redeploy". I tried "clean install tomcat7:redeploy -Dspring.profiles.active=development" and I got:

Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project calories-tracker: Failed to clean project: Failed to delete

Relevant part of development profile configuration:

@Configuration

@Profile("development")

@EnableTransactionManagement

public class DevelopmentConfiguration {


    @Bean(name = "datasource")

    public DriverManagerDataSource dataSource() {

…

    @Bean(name = "entityManagerFactory")

    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DriverManagerDataSource dataSource) {

…   

Relevant part of pom.xml:

<packaging>war</packaging>



    <properties>

        <java-version>1.8</java-version>

        <org.springframework-version>4.1.3.RELEASE</org.springframework-version>

        <spring-security-version>3.2.5.RELEASE</spring-security-version>

        <hibernate.version>4.3.7.Final</hibernate.version>

        <org.slf4j-version>1.6.1</org.slf4j-version>

        <jackson-version>2.4.4</jackson-version>

        <postgres.driver.version>9.3-1100-jdbc41</postgres.driver.version>

    </properties>





<build>

        <finalName>my_app</finalName>

        <plugins>

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-compiler-plugin</artifactId>

                <version>2.3.2</version>

                <configuration>

                    <source>${java-version}</source>

                    <target>${java-version}</target>

                </configuration>

            </plugin>

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-dependency-plugin</artifactId>

                <executions>

                    <execution>

                        <id>install</id>

                        <phase>install</phase>

                        <goals>

                            <goal>sources</goal>

                        </goals>

                    </execution>

                </executions>

            </plugin>

            <plugin>

                <groupId>org.apache.tomcat.maven</groupId>

                <artifactId>tomcat7-maven-plugin</artifactId>

                <configuration>

                    <path>/</path>

                    <httpsPort>8443</httpsPort>

                    <keystoreFile>${basedir}/other/keystore.jks</keystoreFile>

                    <keystorePass>secret</keystorePass>

                </configuration>

            </plugin>

        </plugins>

    </build>
Community
  • 1
  • 1
Jim C
  • 3,957
  • 25
  • 85
  • 162
  • 1
    The tomcat-plugin downloads and starts a "dedicated" Tomcat server, not an "embedded" one. You could either add a server to the server view (static resources will be hot deployed. I dont know why you dont want that), or use for example Spring Boot to get an embedded Tomcat application. You should have a look at JRebel for an example of an excellent hot deployment tool. – Stefan Jul 06 '16 at 07:49
  • I thought tomcat7-maven-plugin was an embedded server. If I understood correctly, you mean that I can add the exact server downloaded by tomcat7-maven-plugin to the server view. I mean, I just started the application with "clean install tomcat7:run-war" from Eclipse/Debug Configuration. Now, how can I add this exact Tomcat server to server view? I right clicked in Server View > new > Server > Apache > Tomcat8 and where is the server just started to be added in Tomcat Installation Directory textbox? As told in my question, "target/tomcat only contains conf and log folders" – Jim C Jul 06 '16 at 17:12
  • 1
    The server files can be found in your Maven cache directory. I think the misunderstanding I have is, that the plugin starts the server progammatically (tomcat-embed-core), while I was thinking about the server being embedded in your application. I think the run-war goal will run your app from the "packed" archive, therefore it wont even change static resources on the fly. Why dont you want to download a server for deployment? – Stefan Jul 07 '16 at 07:52
  • Stefan, thanks for your help. Certainly, in my daily work, I prefer to download the Tomcat and register it. Nevertheless, in order to provide a zip project for didactic purposes, I guess leave all things in Maven hands a bit more friendly. Please, if you are really sure that I can't use "tomcat-plugin download that starts a dedicated Tomcat server" with "change static resources on the fly" idea, answer my question that way so I can point it as the final answer. About the term "embed" I can tell you I learn the correct vocabulary from you (I should mention "dedicated" for tomcat7-maven-plugin) – Jim C Jul 12 '16 at 00:32

0 Answers0