Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can IntelliJ update resources on Tomcat when a file is changed externally?

My company has elected to go with IntelliJ for development and deployment to a local Tomcat server. I have been doing my development on gVim, and have no desire to change.

When we were using eclipse I was able to have eclipse republish resources when the file was changed externally. ( I beleive the setting was Refresh using native hooks or polling) This was wonderful because I prefer to use command line tools to integrated ones.

We are using IntelliJ to manage the server, which I'm okay with, however I would like to not disrupt my current workflow.

I know IntelliJ stays in synch pretty well, and will update the files when I focus on it, and refresh them when I leave the frame.

Is there a way to have intelliJ update resources that have been changed externally ( Gvim, cli git... ext ) without moving to it?

like image 795
BenJamin Avatar asked Oct 21 '22 00:10

BenJamin


1 Answers

Sadly, I have been unable to find a way to monitor external changes and update a Tomcat server inside IntelliJ.

I have implemented a workaround using grunt. ( a node.js task runner )

The theory behind this workaround is simple:

  • Tomcat serves an exploded war
  • grunt watches my front end files
  • when a file changes grunt moves my front end files into the exploded war

Some benefits of doing it this way are:

  • works for any external editor/tool/ect (vim, sublime text, nano, cli git, and any other you can think of)
  • you don't need to move into intelliJ to get your resources updated.
  • no java required to get this solution set up.

Down side is

  • you've got an extra process running.
  • you have another tool to deal with.
  • you need to deploy the front end stuff in exploded wars ( not really that bad in my opinion )

To learn more about grunt and get it set up you can visit gruntjs.com.

This workaround uses two plugins

  • grunt-contrib-copy
  • grunt-contrib-watch

First you set up a task that copies your files into your exploded war. This will use the grunt-contrib-copy plugin and will probably take some finagling, but it isn't too bad. Mine looks like this:

copy:{
    webfilesToOutdir:{
        files: [
            {expand: true, src: ['WebContent/**'], 
             dest: '../out/artifacts/attensity-q/exploded/attensity-q.war',
             rename: function(dest, src){
                    var ret = dest+"/"+ src.replace('WebContent/', '');
                    return ret;
                }
            }
        ]
    }
}

Next you will need a task to watch your files and run the copy when something changes. This will use grunt-contrib-watch and again it is nothing to bad, you will just need to adjust the paths. Here is mine:

watch: {
    web: {
        files: ['WebContent/**', '!WebContent/less/**'],
        tasks: 'copy:webfilesToOutdir',
        interrupt: true
    }
}

I hope this helps. I've been using this solution for some time now and it has done its job pretty well. Good luck, gentle men.

like image 111
BenJamin Avatar answered Oct 23 '22 06:10

BenJamin