Hotswap Agent, add New Classes

1k views Asked by At

can I add new class on Hotswap Agent? I try changing name methods, body of methods, fields, and works fine, but when I add new class and call it on another the app crash, don do the content of that class and not show errors.

package test;

public class TestNewClass 
{
        public void test()
    {
        System.out.println("test new class");
    }
}



@Controller
public class MenuController extends MainController
{
    @RequestMapping(value = "/menu/getMenu", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE_UTF_8)
        @ResponseBody
        public String getMenu(HttpServletResponse httpRessponse)
        {
            System.out.println("test 3 "+test);
            UserVitrina user = getUserVitrina();
            MenuHandler menuHandler = new MenuHandler();
            try
            {
                genericBO.openSessionTransaction();
                Map menu = menuHandler.getMenu(user.getIdUsuario());
                genericBO.commitTransaction();
                return new Gson().toJson(menu);
            }
            catch (Exception ex)
            {
                new Log().printLogError("MENU. Error obtener menu.", ex, (user == null ? "usuario nulo" : user.getUsername()), null, Resources.LogName.DEBUG);
                httpRessponse.setStatus(HttpStatus.BAD_GATEWAY.value());
                genericBO.abortTransaction();
                return new Gson().toJson(new MessageServer().generateMessageError(ex));
            }
            finally
            {
                genericBO.closeSession();
            }
        }
}
1

There are 1 answers

0
edudant On

If you do hotswap with your IDE, it swaps only existing classes. New classes are loaded by standard mechanism from the classpath. Is your new class on the classpath? If you have e.g. multimodule maven project, you may be able to swap classes from dependent module, but new classes are loaded only from built jar files.

To solve this add extraClaspath (http://hotswapagent.org/mydoc_configuration.html) to your hotswap-agent.properties file.