I’m not much of a Java programmer, but seeing as I just wasted a bunch of my day on this, and it’s been a pain every time I’ve set it up, I’m posting this just to get some info out there and hopefully searchable for people who run into similar problems.

A project at work uses maven to build, and produces an artifact that’s not checked in to the github repo. My goal is to have this file get uploaded to my remote development server, and have that get “noticed” and deployed by Jboss. It turns out there are lots of problems to solve, here, so let’s start at the top.

Also: we’re running an old version of Jboss, before it got renamed(?) to Wildfly; Jboss 7. I imagine much of the Jboss part of things is the same anyway, but take that all with a grain of salt.

Step 1 for me was making it easy to actually execute the build. The default view in IntelliJ doesn’t even present the information I needed to do this, and it was buried away under some turn-down arrows. First click “Maven projects” on the right side, or View > Tool windows > Maven projects. Then, find the root project and turn down the arrow next to it. Turn down the arrow next to Lifecycle, and select “package”. If you click the green “play” icon, it should build your project. I guess. I don’t know much about Maven!

I really don’t want to have to dig through this every time, though, or give up screen real estate. So: right click on “package” and click “create yourproject[package]” — this will create a run configuration for that job. You should be able to click OK on the dialog that pops up with the default settings, unless you want to change something. Now, the maven package job will appear in the dropdown in the top right of your IDE, and if you choose it all you have to do is click the green play icon to get it done. Sweet, now I can close that whole panel!

(Side note: apologies for the lack of screenshots, I just want to knock this post out and get back to work… constructing a toy project or editing the screenshots will be a lot of work!)

Now that there’s a convenient way to build my project, step 2 is to set up the deployment part. This menu has behaved very strangely for me, sometimes disappearing, sometimes having items be disabled or enabled seemingly arbitrarily, so I’m going to describe how it seems to work for me, and hopefully will also for you.

Go to Tools > Deployment > Configuration. This is where you will set up the server to upload to and tell which file(s) to transfer. On the “connection” tab, enter the host, port, username, and authentication info. Since this is a dev server that’s on a local network, I am just using password authentication and haven’t tried public key auth. Public key auth is generally better, but at a glance it doesn’t look like an agent is supported so it’s only moderately more useful. I entered my password and checked “save password”. Use the “Test SFTP connection…” button to verify.

Note: SFTP and FTPS are two different things. SFTP only needs SSH access, and was the default type when I set this up. You may select FTP or FTPS if you want, however. I believe there can be some FTP server configuration surrounding the user, group, and permissions files get created with that you can sidestep by using SFTP with the user you intend to own the file.

Next, visit the “Mappings” tab. While the items here say “path”, you can enter either a directory or a file — but if you enter a file for the local path, be sure and also enter a file for the deployment path. I didn’t touch the “web path” option, and am not entirely certain what its purpose is. For Jboss hot deploy, I set the deployment path as “/usr/local/jboss/standalone/deployments/myproject.ear”.

Now, let’s make sure we can upload the file.¬†Find the build artifact you want to deploy. For me, in the project view (left side: project, Alt+1, or View > Tool Windows > Project), it’s tucked away under “dir [packagename] > ear > project.ear”. Find it, and click it to select it. If you click Tools > Deployment, the top menu items should be available. You can also right click the file itself and go to “Deployment” in the context menu. Select “Upload to [yourserver]” and the file should be transferred. A status bar appears in the bottom of the window, and you can view log details by opening the “file transfer” panel. Hover over the monitor-looking icon in the very bottom left to select it.

Step 3 is important! Go to Tools > Deployment > Options. If you don’t check in your build artifacts, this won’t work unless you check “Upload external changes”. While you’re here, make sure you uncheck “override default permissions” on anything, and uncheck “Preserve files timestamps”. If you leave preserve timestamps enabled, Jboss will detect the changed file when you upload it, prepare to deploy it, and then just forget what it was doing as Intellij “helpfully” sets the file timestamp back to what it was before. Symptoms of this may include Jboss refusing to notice new file uploads, and a “yourproject.isdeploying” file present in the deployment directory. Restarting Jboss will get you back up and running. Follow the logs (try /var/log/jboss/server.log) to make sure everything is going as expected. You might have to enable and configure logging to show you deployment information, which is logged under the category “org.jboss.as.server.deployment”.

Finally, and again under Tools > Deployment, be sure and select “Automatic upload”! This will enable change detection for when the build product is complete and upload it to the remote server.

Step 4 is to make sure Jboss detects the uploaded file and loads it. In your configuration file (mine is in /usr/local/jboss/standalone/configuration/standalone.xml), look for or create this structure:

<server xmlns="urn:jboss:domain:1.3">
    <subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
      <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" deployment-timeout="60000"/>

I’m sure my versions are well out of date; this is not a complete config and you should prefer anything already in your config (or, better, understanding how to create / edit the config) over anything written above! The important bit is the <deployment-scanner> element. “scan-interval” defines how often Jboss checks if the file has changed, and “deployment-timeout” defines how long Jboss will wait until giving up on the deployment.

Those are all the bits! Give it a try: click the convenient “build my package” button, watch the log messages scroll by, and hopefully the status bar at the bottom will then read “uploading [your package]…” — and if you’re extra lucky, the logs on your Jboss server will say something like, “Scan found incompletely copied file content”.. followed by “replaced deployment [your package] with deployment [your package]“.

The Intellij deployment options for “upload external changes” (turn it on!) and “preserve file timestamps” (turn it off!) have given me particular grief in the past; if you find that Intellij doesn’t seem to be picking up changes and uploading them, look at the former. If you find that Jboss seems to be noticing your new upload but deployments after the first don’t get picked up / fail, or Jboss is leaving an ‘.isdeploying’ marker file behind, check the latter!

Good luck, and have a better time with this than I did!

Post filed under Things that should be easy.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>