I have a Maven/Spring Boot project built in IntelliJ. As far as I can tell, everything seems to run nicely from within IntelliJ.
I have it setup to package to a stand-alone jar with embedded Tomcat:
<packaging>jar</packaging>
I am using:
spring-boot-starter-parent
So, my understanding is that I don't need "repackage" under an executions tag in my pom file.
I would like to start experimenting with deploying the project, and went in to try to do the build to get the JAR. But the "Run Maven Build" arrow under when I right click the project under "Maven Projects" is greyed out. Any ideas as to what might be the cause of this or what I should double check?
You need to select a plugin which Intellij can tell Maven to run. Since you are using Spring Boot and your question referred to "package to a stand-alone jar with embedded Tomcat" and "deploying the project" the plugin you want to use is: spring-boot-maven-plugin.
So, if you add this plugin to your POM as follows ...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
...then you'll see spring-boot under Maven Projects > project_name > Plugins.
When you select any node under spring-boot, the Run button will be enabled, but it will be disabled for the root node since the root node (i.e. your project) is not deemed to be runnable in and of itself.
Here's a screenshot when selecting the root node (the Run button is disabled):
And here's a screenshot when selecting the spring-boot node (the Run button is enabled):
Clicking on Run Maven Build once you have selected spring-boot:run will cause IntelliJ to invoke the run goal of spring-boot-maven-plugin which will start your application including its embedded Tomcat container.
Related
I am trying to run a spring boot application in intellij 2020.1.1 idea by first generating from spring initializer in start.spring.io then open it with intellij. But when I try the application it doesn't have any output.
Can anyone help me with this? Is this a problem of windows defender?
Try opening the project using the pom.xml file (instead of the project map). File > Open... > select pom.xml
Trust the project when asked.
Run maven when recognized as a maven build.
(Right now there is no maven tab on the right.)
When the maven build is recognized a *.iml will be created and a project configuration will be added to your configurations.
Now you can just press 'run' at the top (or press shift + F10)
Tip: you can also just drag and drop pom files on the start screen and it will open the project.
Click on the run button in Main Class. It will automatically start your project. It worked for me.
I have a maven project with root module called "sample" and two child modules in their own directories "sample-services" and "sample-web". "sample-web" is a war module which depends on "sample-services"
I want to be able to run my server from maven (it could be jetty, tomcat, or any lightweight server) and debug my code without using eclipse or intellij idea j2ee integration (for example in Intellij Idea community edition or other IDE that supports remote debugger) and just by adding a remote debugger.
I could start my app with "jetty:run" and attach the debugger but the problem is that when I change my code in "sample-services" it doesn't pick it up unless I run "mvn install" on that module separately and restart the server.
Is there a better way to be able to debug the app and have the server redeploy the code changes without having to restart the server?
I know eclipse can do this for a maven project. It will detect the changes in dependent project and upload them to the server.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.3.v20130506</version>
</plugin>
EDIT:
I ended up using tomcat maven plugin for now:
org.apache.tomcat.maven
tomcat7-maven-plugin
2.1
/
true
in your pom.xml and run in the command line: mvn tomcat7:run
Downside is that this will reload the whole app upon each change instead of hot-deploy.
So now I am looking for a hot deploy alternative.
So I was following http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/ for a simple tutorial on how to use maven and jsf. I created a maven project by running mvn archetype:generate -Dfilter=org.apache:maven-archetype-webapp in my command prompt. Then I continued with the tutorial, I wound up creating all necessary files, but then when I got to the end, I realized I did have a server created. So I created one real quick, but when it came to the point of adding files to the server (from the add or remove dialog box), no projects or files showed up. I am not on my computer where the project is located so I can't copy/paste the .pom file in, but it looks practically exactly like the pom in the tutorial (only difference is groupId, artifact, ect.) No additional plugins, dependencies, or configs.
Do you want to deploy the webapp within Eclipse to Tomcat? Or as some sort of automatic/continuous deployment?
Within Eclipse you often need to add the Dynamic Web project and JSF facets to your project so Eclipse recognizes the project as deployment capable. If you are using m2eclipse make sure to install the m2eclipse wtp add on so this is done automatically.
If you want to add auto-deployment to the pom.xml I recommend using the maven cargo plugin: http://cargo.codehaus.org/Maven2+plugin - it supports the major containers.
For tomcat you need to modify the tomcat-users.xml to allow auto-deployment and leave the tomcat-manager application in place. If you have startet tomcat and pointing your browser to http://localhost:8080/manager/html/list it should either tell you to login or what to add to that file.
The configured user is then used in the configuration to deploy the war file via the tomcat-manager using the mvn cargo:deploy goal. The configuration has to be added to the pom.xml using war as packaging, not to the parent-pom.xml
As we all know, suppose we define 'transportation' in pom.xml in maven,
after we run command like 'mvn jetty:run' the property 'db.name' can be discovered by other configuration, like 'hibernate.cfg.xml'. That's fine.
But now, I configure this project to run on tomcat directly , by 'run on server' from eclipse, instead of by maven command. (I did this by configure a project facets in eclipse, make it can use 'run on server' menu). You can see now I just run with eclipse, nothing to do with 'maven' or 'pom.xml', but it still use properties like 'db.name'. If I need change to another db, I had to change the 'db.name' property, then run some command in maven to make it take effect.
Can any body give some explanation about how it works? Does maven command generate some file at some place that takes the properties?
Properties are set for virtual machine. Maven run new/existing (dependent on configuration) instance of runtime environment. So you can pass properties as
-Dkey=value (or <key>value</key> in pom)
Check in eclipse configuration if you can pass arguments when you run tomcat?
Eclipse maven plugin (from Eclipse foundation) understands the pom.xml and usually syncs with any changes.
But sometimes I observed that it goes out of sync, and to fix that problem I need to delete the temporary folders/files created by Eclipse (.settings, .classpath and .project) and import again.
I'm using Eclipse + Maven + m2eclipse to build and test a web application in Apache Tomcat.
I've configured a Tomcat server inside Eclipse, and configured the deployment assembly for my web app, including "Maven Dependencies" (specialization of Java Build Path Entries).
When I deploy and start the server, Tomcat/Catalina always warns me:
INFO: validateJarFile(/projects/src/main/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp/WEB-INF/lib/servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
This is because m2eclipse sees servlet-api-2.5 as a dependency of my project, and considers it as part of "Maven Dependencies", and copies it as part of the deployment assembly, but the Tomcat servlet container has its own copy of this and doesn't like seeing 2 copies on the class path.
I've marked the dependency from my project to servlet-api-2.5 in my pom.xml with
<scope>
provided
</scope>
which does prevent standalone Maven from packaging servlet-api-2.5 into my builds, but m2eclipse doesn't see it that way.
(This isn't a huge deal because the warning is harmless, I only see it during testing inside the IDE, and real customers won't see it, but I'd still like to know how to fix it because I like cleanliness and I like knowing how things work.)
Is there a correct way to tell m2eclipse not to deploy this file, or to tell Eclipse not to let m2eclipse have the final say on which dependencies are runtime dependencies?
I did find https://issues.sonatype.org/browse/MNGECLIPSE-1193 which mentions
the "Maven Dependencies" container reflects test compile time scope, so it is supposed to have dependencies with scope "provided"
Install extras for m2eclipse plugin ("Maven Integration for WTP") from update site http://m2eclipse.sonatype.org/sites/m2e-extras. After install, update the project configuration.
Normally there is a dependency in your project that is depending on servlet-apĂ®.jar
The default behaviour of Maven is that i wiill try to import your dependency + the dependencies of the imported dependency.
If you want to exclude a specific "sub-dependency", you can give maven a configuration like this :
<dependency>
<groupId>com.hpsworldwide.mbtrs.switch</groupId>
<artifactId>YOUR_DEPENDENCY</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
then maven will import YOUR_DEPENDENCY + all YOUR_DEPENDENCY dependencies, but will exclude servlet-api from the dependencies of YOUR_DEPENDENCY.
I have just had a similar problem, and believe I have got to the bottom of it.
If you go to your server configuration settings in Eclipse and select "Serve Modules without Publishing" then this should no longer occur.
Maven/M2Eclipse is building the WAR correctly - servlet-api-2.5.jar wont be in your target directories or WAR file.
But the problem is, when you deploy the application via eclipse on to your tomcat, Eclipse does not use your maven built WAR/target directories as default, it just uses the normal Eclipse "export" settings for your project. So it sees in your "Java EE Modules" (or "Deployment Assembly List" if you are using Helios) the list of all the jars in your Maven_Dependencies, but it does not respect the scope, and just deploys all the jars.
If you select serve without publishing option then Eclipst/Tomcat should just run the app straight off your target directory so will respect the maven scopes.
It won't ever affect your live deployments (unless you are deploying via eclipse!) as maven is doing the right thing, but it can sometimes cause problems locally as you can ave conflicting servlet/jsp jars which can cause classcastexceptions and general misery...
If you are using Indigo you can find the WTP plugin by clicking to "Window" -> "Preferences" -> "Maven" -> "Discovery" -> "Open Catalog".
One tip: after install "Maven Integration for WTP" and update the project configuration, check the directory /WEB-INF/lib and delete all JARs inside. Now, clean the Tomcat work dir and run again.