Using Tomcat Maven plugin with multiple servers - maven-2

I've looked at the usage, but haven't understood from it how to configure multiple servers. I added separate server elements to settings.xml - but I don't understand how to specify a different URL for every server.
The URL element belongs to the global plugin configuration. How do I configure multiple server URLs?

You could add multiple profiles to your pom.xml. One for each server. Check the Maven documentation on profiles for details!

If you examine the documentation of the Tomcat plugin you will see that it does not support multiple <configuration> sections. That should be a small addition because in the deploy phase you only copy the WAR file to the server using an HTTP PUT command. So I wonder why they have not added this capability to the plugin.
Anyhow, one possible workaround is to:
Make multiple copies of your pom.xml in the same directory but give them unique names, e.g. dev_1_pom.xml, or dev_<some_machine_name_or_IP>, qa_1_pom.xml ..... You can keep your development pom.xml file name the same because you will likely still run Maven from the command line. Personally, I prefer running the mvn command from my IDE (a button click away vs. typing an mvn command with arguments every time).
In each of the copies, change the <configuration> section under your Tomcat plugin to point to a different server that matches the name of your specific pom.xml. You will need corresponding sections in settings.xml
Create corresponding External Tools Configuration(s) (Eclipse, or other IDE) and each one call the corresponding POM file. Here is an example with Eclipse:
Open External Tools Configuration Dialog in Eclipse (either from the dropdown menu next to the button, or by going to the menu bar and clicking Run > External Tools > External Tools Configurations). Then on the Main Tab, provide values for the following fields
Location: C:\downloads\tools\apache-maven-3.0.3\bin\mvn.bat
Working directory: ${workspace_loc:/<project_name>} - replace <project_name> with the name of your project
Arguments: -f <pom_file_name> <other_arguments> - <other_arguments> could be tomcat7:redeploy
Now you can run these external tool launchers individually to deploy to different servers.
Optionally, extract the mvn commands from your launchers and create a shell script (batch or Unix bash script) that runs all of them. That way you can deploy to multiple servers at once. You can also run this script from Eclipse. Create a new External Tools Configuration launcher but this time your Location: field will point to cmd (Windows) or bash (Unix, Linux ...), not mvn

Related

Buildsteps after each other

How do I run several buildsteps after each other in IntelliJ? I think I want a mini CI/CD build system inside the editor.
For example, the project I work on now is a Spring boot and javascript web site. I need to build it with maven with mvn clean package -Pdockerimage. This copies files for building the Docker image to target/dockerimgbuild.
Then I want to build the docker image using docker build -t scheduling-ui-dev . and after that run it with docker compose docker-compose up --build from src/main/resources/docker-compose.
I have built one run configuration for each of these steps but how do I run them after each other? I have found that you can have before launch but the system is clunky and complains if target/dockerimgbuild doesn't exists even before it have run the maven step which creates it. Latest problem I stumbled on was that a file prevented maven from removing target/dockerimgbuild and all run steps was automatically removed from the run configurations.
There is a run configuration called compound but that runs everything in parallell and you can not specify order which is a problem.
I wonder if it is feasible to start TeamCity in a container, do anyone have a clue about that (is teamcity easy to configure, how to make it launch a docker-compose container on my host machine etc)?
My solution right now is to have several terminals (if this gets more permanent I will replace it with a script) where I just press up and enter to execute the steps manually. Seems stupid as I guess maven itself can do all of this...but I don't know how or how much work it is.
There is a compound Run/Debug configuration: https://www.jetbrains.com/help/idea/run-debug-configuration-compound-run-configuration.html
Also, there is a multi-run plugin: https://plugins.jetbrains.com/plugin/7248-multirun

selenium-server-standalone.jar maven dependency

I am using Maven as a build tool. On selniumhq site I can see selenium-server-standalone.jar file but I could not found related Maven dependency. Is there any maven dependency for selenium standalone file?
latest selenium standalone file is : selenium-server-standalone-3.2.0.jar
Note : I want to execute code on Remote desktop machine using Selenium grid (which require aforementioned jar file)
I think you should refer to this manual first: http://www.seleniumhq.org/docs/07_selenium_grid.jsp#starting-selenium-grid
i.e. in order to use grid you need you need to create grid instance first by running commands
from command line, then you need to register node, again by using command line, and after that from your code you need to create instance of RemoteWebDriver (refer to this page for more details: http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#remotewebdriver).
If, for some reason, you want to to create grid\register nodes from your project maybe it makes sense to download it to your resources folder, execute it from there using Runtime (refer to this link for more details: http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html) and then connect to it. But I would strongly recommend avoiding doing so.

Gradle Script parameters(such as -Penv) with Intellij

Background:
I've been using Eclipse for a while and am trying out Intellij now.
I checked out my project from Git (via Intellij) and recognized it as a gradle project. Its created the WAR(& the exploded WAR) all of which are fine.
Question:
When I was using Eclipse, I used the command:
gradlew -Penv=Development :my_webapp:assemble
This used to do a few things including creating a environment.properties file that my dev specific env could use (for selecting database instances etc) based off of -Penv=Development...I'd like the Intellij gradle build to do the same... What's a way to configure Intellij's gradle process to do these custom things or provide same features as provided by this specific command line tool (Note - the code for this is already written in build.gradle file)...
I looked at some of Intellij's docs, but could not find an answer to this.
EDIT:
I've found the solution, for anyone interested - read on...
Seeking guidance from #Stanislav, I was able to add the property as follows:
In your server's run configuration (Run/Debug Configuration -->Your server's config(Jetty etc), there is a section called Before launch, which should have Make/Build Gradle already included
Hit the + sign -->Run Gradle Task --> Select your gradle project (i.e. the web app) --> Select the task (most likely loadEnvironmentConfiguration) --> set the script parameters such as -Penv=Development, hit OK
Move this to before the Build Gradle function (by using the up arrow - to the right of + sign you hit in step 2)
It seems, that you need to create your specific run or debug configuration. You can read about it in official IntelliJ Idea help. All you need, is to modify your configuration for the task you need, by providing the argument -Penv=Development, since it is running with gradle.
You may also need to define Gradle instance, which will be used via settings, if the defaul wrapper wont work for you. You can find almost all you need in the the official help.

Can I commit and share VM options in IntelliJ?

To execute my application, or run or debug unit tests, I need to enable various VM options, include -javaagent:<aspectjweaver-path> or -Djava.library.path=<some native lib path>
I can see how to change these configurations manually in IntelliJ IDEA under "Edit Configurations..."
What, if anything, do I need to check in to my VCS to share these settings with other members of my team, and ensure they pick them up automatically whenever someone changes them in the VCS?
Alternatively is there a way to set these automatically in IntelliJ without even touching the edit configurations? Especially the aspectjweaver. When I build/test my project from the command line using maven this is all handled for me by specifying argLine arguments to the surefire plugin, but IntelliJ doesn't respect these settings. Perhaps there are alternative plugins that can help me out?
First, you need to share your run configuration. It's simply done by checking the Share box right to the configuration name in the run configuration dialog:
Your run configuration will then be saved to .idea/runConfiguration (or whatever your settings folder name is).
From Jetbrains Web Help:
If this check box is selected, the run/debug configurations become available to the other team members.
The shared run/debug configurations are kept in separate xml files under .idea\runConfigurations folder, while the local run/debug configurations are kept in the .idea\workspace.xml.
This field does not appear for the default run/debug configurations.

How can I get Eclipse to use my IVY_HOME variable when downloading ivy dependencies?

My company uses extensive use of ivy to download dependencies. Some of these dependencies are huge (~500MB) and take a while to download from the remote repositories.
To build our application we have an ant script that will first resolve all the dependencies and the deploy to the server.
I have set an "IVY_HOME" environment variable so that all the dependencies are downloaded to D:\ivy_home instead of C:\Users\.ivy2\ - this is because D: is my SSD which is significantly faster, and it is where my local server directories are located - so copying files from ivy_home to the server is super fast.
But for some reason when I am using IvyDE plugin inside eclipse - it always wants to download a separate copy of all the dependencies and puts them into my C:\ which is causing several issues:
Local publishes from the ant script will not be picked up in eclipse since they are placed into a different location
Dependencies already downloaded in D: will not get picked up which makes the ivy Resolve inside eclipse much slower than it needs to be
The dependencies are in a slower drive in eclipse so performing searches, and executing these jars is also slower
How about creating symlink to replace the .ivy2 in Users to D? I've tried it on my own and it's looks working fine.
Open cmd as root, and then execute this line
mklink /d C:\Users\{username}\.ivy2 D:\.ivy2
I'd create an ivysettings.xml file and specify the location of my cache using the caches directive. See the following answer for example:
can I turn off the .ivy cache all together?
Why don't you set up IVY globally with the ivysettings.xml along with a property file.
This property file could have this:
ivy.default.ivy.user.dir=D:\ivy_home
For individual projects you could uncheck "enable project specific settings" for each IvyDE library management, so they would use IVY global settings, with one extra eclipse environment configuration.