Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:09:22+00:00 2026-06-06T16:09:22+00:00

I have written an OSS plugin to start/stop Derby during a Maven build process.

  • 0

I have written an OSS plugin to start/stop Derby during a Maven build process.
The plugin works fine in plain old single modules. However, if I have an aggregator of several modules and more than one of them has database-related tests, I seem to be hitting some weird problem.

I am invoking the plugin’s start and stop goals (respectively during the process-resources and test phases), as shown below:

        <plugin>
            <groupId>org.carlspring.maven</groupId>
            <artifactId>derby-maven-plugin</artifactId>
            <version>1.4</version>

            <configuration>
                <failIfAlreadyRunning>false</failIfAlreadyRunning>
            </configuration>

            <executions>
                <execution>
                    <id>start-derby</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-derby</id>
                    <phase>test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

The problem consists in the fact that upon the second attempt to start the Derby (in-memory) server, Derby appears to still be running, or to have loaded with the database contents from the first module. I can tell this because the first module in the aggregator creates and populates some data in a table. My expectation is that once I’ve shutdown Derby and started it all over again from the other module, that it would be a fresh database without any existing contents.

Here is my code inside the plugin that deals with shutting down Derby:

try
{
    try
    {
        server.ping();
    }
    catch (Exception e)
    {
        if (failIfNotRunning)
        {
            throw new MojoExecutionException("Failed to stop the Derby server, no server running!", e);
        }

        getLog().error("Derby server was already stopped.");
        return;
    }

    server.shutdown();

    while (true)
    {
        Thread.sleep(1000);
        try
        {
            server.ping();
        }
        catch (Exception e)
        {
            getLog().info("Derby has stopped!");
            return;
        }
    }
}
catch (Exception e)
{
    throw new MojoExecutionException(e.getMessage(), e);
}

The full source of this rather simple plugin can be checked out or viewed in GitHub here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:09:25+00:00Added an answer on June 6, 2026 at 4:09 pm

    I ended up doing the following:

    try
    {
        try
        {
            server.ping();
        }
        catch (Exception e)
        {
            if (failIfNotRunning)
            {
                throw new MojoExecutionException("Failed to stop the Derby server, no server running!", e);
            }
    
            getLog().error("Derby server was already stopped.");
            return;
        }
    
        try
        {
            DriverManager.getConnection(getConnectionURL());
            DriverManager.getConnection("jdbc:derby:;shutdown=true");
        }
        catch (SQLException e)
        {
            // Apparently this prints out a bunch of stuff we're not currently interested in,
            // we just want it to shutdown properly.
            // Perhaps further handling might be required at a future point in time.
        }
    
        server.shutdown();
    
        while (true)
        {
            Thread.sleep(1000);
            try
            {
                server.ping();
            }
            catch (Exception e)
            {
                getLog().info("Derby has stopped!");
                break;
            }
        }
    
        System.getProperties().remove("derby.system.home");
    }
    catch (Exception e)
    {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    

    This wasn’t the way I expected it had to be done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this code in JavaScript and works perfectly fine when I include
I have written a java program which different classes where during the process it
I have written a function for browser compatibility. When I pass objTR.cells[0] it works
I have written a small HTTP server and everything is working fine locally, but
have written this little class, which generates a UUID every time an object of
I have written a bash script which installs a number of packages, however for
I have written this code inside a servlet to delete certain records from three
I have written a function that sorts a big scale of data. To test
I have written a java program generates lots of files (say txt files) in
I have written a function that extract the domain from hostname. e.g. www.domain.com ->

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.