IntelliJ IDEA - Run/debug doesn't copy resources - maven

I have a maven project which is packaged as WAR. The POM looks something like the following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>my_app</artifactId>
<packaging>war</packaging>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
...
</plugin>
...
</plugins>
</build>
</project>
When I manually run the command mvn package, a WAR is generated with directory target/my_app where my web resources (JSP, CSS, JS, images, etc.) are copied to. The generated WAR, if uploaded to an Application Server, works fine.
However, if I use IntelliJ IDEA's Run/Debug configuration (which is configured to deploy the WAR to an Application Server (JBoss if that matters)) to do the same, I don't see the web resources. Only configuration XMLs and compiled classes is present in the target/my_app directory. The applicaiton server starts up all fine without any errors and WAR is deployed successfully, however I can't accesss it as it returns 404.
How can I acheive what I get when building and manually uploading the WAR using Run/Debug of IntelliJ IDEA?
UPDATE:
Before launch tasks are:
Build
Build 'my_app:war exploded' artifact

I had the same issue after installing 2018.1 IntelliJ IDEA. Reverting back to version 2017.3 solved the problem. It looks this is a bug with the new version since I had the same settings for both. Hope this helped.

I had similar issue in which when I was running from the command line then it was copying all the resources (example JSP etc.) but Intellij was not copying it.
As part of workaround I added the goal of 'war:exploded' along with 'compile' then it resolved my issue.
So in Maven config command line parameters will be (may differ for you):
clean compile war:exploded
Screenshot for reference.

Related

maven fails to recognize jetty is installed

fresh meat newbie on GCP / Maven on
OSX 10.14.3 with Visual Studio Code (latest)
GCP SpringBoot API with Maven
other questions on jetty seem to be further along than me.
the 'flow' below is to reveal steps to get to my question in the title...I think it's important to see how I got to where I am, and if you are so kind to offer help, you would want to know this? ok, here we go...
I downloaded the GCP getting-started-java github example and want to run the bookshelf example.
When I look at the multiple POM files I see that each references a project ID for GCP.
I can't use the same project ID as they are unique, just like GCP bucket names.
So, when I run
gcloud init
and select or create a configuration and make my own project with a unique project id, does that automatically override every POM file definition of project ID? Or do I need to do some maven clean command to change it???
Well... when I RTFM in each folder, it says to
mvn clean jetty:run-exploded -Dbookshelf.bucket=MY-BUCKET
heck even tried:
mvn jetty:run
and I get a build failure that says:
[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups
so... I
brew install jetty
Then to 'get started' jetty says I have to copy the 'plug in' details into my POM file... which one, as there are several??
But when I installed the VS Code plugin, it already updated all POM files; I still get the "No plugin found for prefix 'jetty'" error
I guess I'll stop with that question:
how do I get maven to 'know' that jetty is installed and work with it?
When you use the shorthand plugin goal jetty:run-exploded or jetty:run maven is attempting to find the plugin. This shorthand form will need to resolve the groupId:artifactId:version:goal in order to run.
The long-hand form of that would be ...
$ mvn org.eclipse.jetty:jetty-maven-plugin:9.4.15.v20190215:run
To fix this, just add the plugin to your pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.15.v20190215</version>
</plugin>
</plugins>
</pluginManagement>
...
</build>
</project>
The above will always use that specific version of jetty-maven-plugin when you use the shorthand syntax.
Alternatively, and with less control over which version to use, is to setup a pluginGroup in maven's $HOME/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<pluginGroups>
<pluginGroup>org.eclipse.jetty</pluginGroup>
</pluginGroups>
...
</settings>

Continuous Integration with Talend and Jenkins/Maven

I have a Talend studio Enterprise veresion 6.4.1. I have downloaded the CI builder and installed with maven using the below command.
mvn install:install-file -Dfile=ci.builder-6.4.1.jar -DpomFile=ci.builder-6.4.1.pom
I have exported the job from Talend studio put into the Git. It contains the following files.
1) process a) .items b) .properties c).screenshot
2) talend.project
I have created a pom.xml with the below details
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.talend</groupId>
<artifactId>buildsources</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.talend</groupId>
<artifactId>ci.builder</artifactId>
<version>6.4.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I have placed pom.xml in the root folder of commandline workspace.
I placed the checked out folder inside command line workspace .
After that I executed the commandline.bat inside Talend studio to start the Talend.
I tried executing the below command to generate the source file.
mvn org.talend:ci.builder:6.4.1:generate -X -Dcommandline.workspace="D:\ci-builder\commandline_workspace\TEST" -Dcommandline.host=localhost -Dcommandline.port=8002 -Dcommandline.user=dummy#talend.com -DprojectsTargetDirectory=D:\buildsources\
Now it is able to find the project but at the end it says no job
[INFO] Preparing for the project: TEST
[INFO] Logon project
[INFO] Generating sources...
[INFO] Logoff project
[WARNING] There's no job in current project!
I am using Windows machine to test this - Windows 10 64 bit.
Maven version is 3.5.3
I have been referred the below links for doing this.
https://community.talend.com/t5/Architecture-Best-Practices-and/Continuous-Integration-with-Talend-CI-Builder-6-3/ta-p/33033
https://akhileshthipparthi.wordpress.com/2017/01/23/talend-ci-using-jenkins/
But when I check the .Java folder in my Talend installation directory command line workspace, I can see some files generated. pom.xml and pom_routines.xml. But there are no job related files getting generated.
And with those pom.xml , if I do a mvn clean install, it is generating a routines.jar file only in the target directory.
I am not able to proceed further.
Any pointers will be helpful.
One thing I wanted to highlight is that, for talend CI builder to work there is no need to writing test cases.
I was able to build the job using the CI builder using the below steps.
Inside the command line work space, you need to keep the complete project structure.
Checkout the source files from Git and copy the files to the project folder.
All the source files will be present inside the process folder of the project folder.
Setup the maven repository for Talend command line. It will be inside the configuration folder inside the Talend folder.
Execute the below command to Generate the source code inside the command line workspace.
Here SayHello is the Job name.
mvn org.talend:ci.builder:6.4.1:generate -Dcommandline.workspace="D:\ci-builder\commandline_workspace\" -Dcommandline.host=localhost -Dcommandline.port=8002 -Dcommandline.user=dummy#talend.com -DprojectsTargetDirectory=D:\ci-builder\target -DitemFilter=(type=process)and(label%SayHello*)
if there is a parent child job, we need to place all the jobs inside a folder and we need to refer that path during generate source.
Here Sample is the folder name
mvn org.talend:ci.builder:6.4.1:generate -Dcommandline.workspace="D:\ci-builder\commandline_workspace\" -Dcommandline.host=localhost -Dcommandline.port=8002 -Dcommandline.user=dummy#talend.com -DprojectsTargetDirectory=D:\ci-builder\target -DitemFilter=(type=process)and(Path%Sample*)
It will generate the source files and it will be kept in "D:\ci-builder\target"
Now navigate to that path and do mvn clean package
The job will be built and it will be placed inside the target folder. It will contain all the related Jar's, shell script, batch script and libraries and routines. Also it will have the entire folder structure.
Note : If you get the message like, there is no job in folder, just check if there is any error in the talend command line shell. Mostly u can encounter, the .Java folder is missing in command line workspace or there will be dependency errors (missing Jars in the maven local repo).
As mentioned in the prerequisites section of the Talend documentation you linked, your jobs must have a test case
Talend Jobs
Jobs containing test cases for Continuous Testing
Otherwise they won't be detected.
Please create a test case for your job, and try again.

How to make a WAR file from angular 2 (angular-cli) project?

I want to make a war file to deploy the angular2 project in an apache tomcat server. I made a maven project and inserted the angular2 project inside it. Then I made the webapp folder(instead of the dist folder in the angular2 project) in the src/main in the maven project using angular-cli. When I run the apache server it shows the following errors.
Error loading http://localhost:8080/vendor/angularfire2/angularfire2.js as "angularfire2" from http://localhost:8080/app/app.module.js ; Zone: ; Task: Promise.then ; Value: Error: Error: XHR error (404 Not Found) loading http://localhost:8080/traceur(…) null
This looks like the troublesome dependency is the angularfire2. How to figure this our? Btw, I use angular2 rc-5.
I wanted to post a complete answer to this question since there are lots of views to this question.
The answer works for all angular 2+ versions.
The procedure is as follows.
First you need to create a POM file in your project's root directory. Include the following code into the POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd http://maven.apache.org/POM/4.0.0 ">
<modelVersion>4.0.0</modelVersion>
<groupId>it.your-company</groupId>
<artifactId>your-project-artifact-id</artifactId>
<version>1.0.0</version>
<name>your-project-name</name>
<description>Any description</description>
<packaging>war</packaging>
<build>
<finalName>target-file-name</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>dist</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.build.finalName}</path>
<update>true</update>
<url>http://localhost:8080/manager/text</url>
<username>tomcat</username>
<password>tomcat321</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here, I have included the maven war plugin to build the war file as well as the maven tomcat plugin to run the war using IntelliJ idea.
Then you need to change the base URL of your index.html file as base href="/target-file-name".
If you are running the war using maven tomcat plugin, the URL for your app would be http://localhost:8080/target-file-name
Now build your angular project using ng build --prod. This will create all the required deployment files (build files) in the dist folder.
Now run mvn clean package to package your build files to a war file. The war file will be created inside the target folder from your root directory of your project.
(Optional) You may also run the war file using maven tomcat plugin too.
If you want to deploy locally. Say specifically at localhost:8080(Tomcat) , go to the service.msc and start tomcat Services. Build your angular 2 /angular 4 using (ng build). Now open the angular project folder and copy the files inside the dist folder to a new folder say(webui). Open index.html page and give as . Copy this folder to "C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps". Go to browser and type localhost:8080/webui.
This is how i deployed my angular 4 static content in tomcat.
Hope this helps you.
In your index.html set base href to "" or in your case (tomcat) to "webapps" that works for me

Deploying Maven project to JBoss AS7 (standalone)

I am new to JBOSS AS7, and am strictly using MAVEN 3 via command line. I would like to deploy the *.war of my project to JBOSS AS7 without ECLIPSE. I have spent couple of days Googling and trying out difference approaches. I am able to deploy the *.war to Tomcat. I would highly appreciate any help on this. So far this is what I have done:
I have entered the server info(Jboss) to C:\maven\conf\settings.xml
I have included the plugin to the POM
I think I may be declaring the path to JBoss AS7 within my JBOSS plugin wrong.
This is how I am including the plugin in the POM file:
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.0.2.Final</version>
<configuration>
<url>http://localhost:8080/
<server>jboss</server>
<path>/web-app</path>
<configuration>
</plugin>
</plugins>
Did you have a look at the README on the corresponding GitHub page:
https://github.com/jbossas/jboss-as-maven-plugin
When deploying to your localhost (which is the default value) you don't need to define the <url> in the <configuration>, as well as the <server> and <path> elements (besides: I haven't seen a folder named wep-app in AS7).
We run a project where this works even without touching the settings.xml.
So when you have checked this, post what exactly goes wrong, what is the concrete failure message and what is the maven command you use (mvn jboss-as:deploy).

how to let maven war plugin to create multiple war file

i used selenium-mave-plugin for integration test, which require the war file named: project.artifactId-version(say: myproj-0.1-SNAPSHOT.war) while the default war created by maven-war-plugin is project.artifactId.war(say myproj-SNAPSHOT.war).
in order to let selenium plugin, i override the maven-war-plugin in that selenium profile as:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<warName>${project.artifactId}-${project.version}</warName>
</configuration>
</plugin>
now when i build the project, it failed at rpm:rpm, complaining:
source location ..../myProj.war does not exist
my question is if it's possible to create 2 war files: myProj.war and myProj-0.1-SNAPSHOT.war so both rpm and selenium plugins are happy? Thanks
For rpm plugin, please make sure you use the location directive. If you need further help, please post your full pom.xml.
As for selenium, it doesn't really need to know where your .war file resides. Only the web application server needs to know. Sadly, you didn't provide information in which phase of maven the "does not exist" error occured. So I can only guess it's while starting jetty, tomcat or another web application server.
You should run your full build (including tests) with: mvn clean verify integration-test rpm:prm.

Resources