I am using Eclipse ,Spring,tomcat server,maven.
I need to pass some parameters when i build the project with maven.Everything works fine when i do that using command line or when i right click on POM.xml and run it making run configuration changes in eclipse.
But as soon as i start my tomcat it is not able to find the value i want to pass in the parameter and it gives an exception
: Could not open ServletContext resource [/WEB-INF/classes/properties/application-${spring.profiles.active}.properties]
here ${spring.profiles.active} should be replaced the the argument value.
So eclipse is not using maven with argument to build and deploy on the server automatically.
Insert the required maven plugins (especially maven-eclipse-plugin) in the pom.xml for compiling the code and use the command mvn eclipse:eclipse in the project's base directory. This will do the required stuff to create a maven project in eclipse.
This is a very complicated subject where many things can go wrong. You need to be very explicit of how you are running tomcat. Are you using wtp? WTP would be the panel that says "Servers". Is this spring boot? Do have the m2eclipse wtp plugin installed (its very hidden and not easy to find)?
One easier way to get this right is just use springs version of eclipse.
Related
I am working on a project that I need to build a maven pipeline for versioning and release.
I am doing like this:
Change version manually by running mvn versions:set -DnewVersion=2.0.0.
Check the project detail and detect if it is snapshot or release. I have my own custom plugin and a parameter which returns the final version, e.g. 2.0.0-SNAPSHOT. BUT HOW CAN I return this value and feed it to another plugin?
I compile the project and generate the jar with new name, from 2.
And...
I know I can handle every step by a CL command but what I want to know and confused me is that how to embed everything in pom.xml and just run mvn install and nothing else.
Each plugin needs some arguments that should be able to change that. I know I can use the <argument> tag under <configuration>, but some of the plugins do not have the argument tag.
How can I have a solid solution and config everything in my parent POM beforehand?
Also I do have my own plugin but I am not sure if it is possible to embed all things to that and I just run myplugin:Install.
For building a SNAPSHOT, you usually just run mvn clean verify on your project. If you need special plugins, you can configure them in the configuration section following the advice in the plugin description.
For building a release version, you should use a build server (like Jenkins). There, you can construct all the steps much easier than in Maven. If for some reason, you cannot do that, use the maven release plugin.
I'm using IntelliJ IDEA Ultimate 2016.3.2 as my IDE, and I would like to create a run/debug configuration that builds my Java 8 app with Maven, and deploys it to a local Wildfly 9.0.1 standalone server.
So far I have managed to create a configuration that deploys a .war from external source to the Wildfly with debugging, and it works as intended. The external source points to a .war that i manually build with Maven through a command line.
This fulfills my needs, but I would like to include the maven build in my run/debug configuration, to simplify the process.
I need to pass some arguments to my mvn install command.
How can I include the Maven build with arguments in my run/debug configuration in IntelliJ IDEA?
I ended up adding an execution of a Maven goal to the run/debug configuration. Under the "server" tab, I added the Maven goal, which lets me execute my Maven command in a specified directory, to the "before launch" list. I removed the IntelliJ "build" from the list.
The deployment is still an external source pointing to the .war which is now build as part of the configuration.
This works for me, but if anyone has a better approach, feel free to add it.
I have a fairly complex Java EE project which can be built fine from Maven. After importing it to IDEA, I had set up a working deployment of the frontend WAR and the backend EAR to a local Weblogic 12c server. The project also have several 'common' artifacts packaged as jars and used by both the frontend and backend artifacts. For deployment, I used the exploded artifacts to save some time on packaging/unpacking, everything works fine till that point.
During development, I edit some Java sources and try to redeploy the updated artifacts to the running Weblogic. I press Shift+F10, choose Redeploy artifacts, I see IDEA building the project, the project redeploys on the server, and more often than not, I do not see any of the recent changes. Even if I choose Rebuild project explicitly and then try to redeploy artifacts after, no changes can be seen on the server. The only safe way to make my changes appear in the deployed artifacts is to invoke maven from the command line calling the package goal, and then redeploying from IDEA. (No JRebel is installed, is being used either in the IDE or on Weblogic, and I'd like to stay that way).
Is that expected behaviour from IDEA? Could this be something specific to our project or something global? Should IDEA be able to discover which projects needs rebuilt and repackaged and then redeploy the EAR/WAR artifacts properly to the server? Does it need any help from my side achieving that goal?
Whats your run/debug configurations? Check this, if not already sois not.
in the quick menu, edit configurations > Run/debug configurations window:
Server tab:
On 'update' action: restart server
Before launch: set 'run maven clean' and 'run maven install'
Deplowment tab
inserts your ear's here.
don't sure this specific answer your question but what I can suggest you is to try configure
weblogic maven plugin
then you can execute deployment from command line / or from IDEA with maven support.
http://docs.oracle.com/cd/E21764_01/web.1111/e13702/maven_deployer.htm
http://www.youtube.com/watch?v=hagaMr6UL6U
Evenif your final goal is to do the whole built process done by IntelliJ build and deployment options I will first try the following:
If your project was set up properly in maven you should be able to load you maven pom.xml within you IntelliJ. All the maven build commands and deployment setting you were doing through mvn command line will show up in your IntelliJ's maven panel in a nice three structure.
If this works out then clearly one of the libraries that are built through your IntelliJ build are not being deployed properly into the right location. You need to narrow down which one of the jars, the ear, or the war has to be affected by a single change you make and then check whether the date of the file is updated in the location it is to be deployed or not.
To wrap up, my humble sugestion though is to use either maven or gradle intelliJ panels for your J2EE projects. As you do achieve the defined goal of having your project built completely through the IntelliJ idea. Also whatever plugin you add to your maven shows up in you idea's maven/gradle panel. It is a fairly straight forward approach and you achieve a powerfull and flexible deployment and build tools within IntelliJ like your wanted.
I found an annoying issue working with m2eclipse in Eclipse.
My workspace contains 2 projects, an application A and a library B. The application A POM has B as a dependency and everything works correctly. (The project dependecy is found and used when I build the application)
But if I change some code in project B and I forgot to mvn:install it, when I build the application it uses the last built version of the library and it loses my last changes.
Is there a way to force Maven / M2Eclipse to check if the source code of the dependecy is newer than the last version built, and to install it when installing/ deploying the main application?
Or maybe my approach is wrong or is something obvious that I'm missing?
You can tell m2eclipse to use resolve dependencies from the workspace rather than through the normal mechanisms. In your project properties (NOT workspace properties), select Maven->Resolve dependencies from Workspace projects.
This will mean that when you change B and subsequently build A, the changes should be picked up automatically.
If, however, you build outside Eclipse, you'll have to do the normal mvn install to get the correct dependencies.
I don't know of a way to tell maven to build the library first, then build your project. You could put two maven commands into a script and run the script.
Alternatively, you could put both projects inside a maven parent project, and then build the parent. This causes all child project to be built too (so in your case the library, and the application).
I think you have couple of options here
If you can change the maven project set up, I would suggest you to use maven multimodule
Option two might solve your problem but still involves a manual stop when you change your dependent project B, Do this on for your dependent project in eclipse
Select Library B ==> Properties ==> Maven ==> in the input box under Goals to invoke after project clean: ==> enter : install
To deploy any change that you made to Project B in eclipse to maven local/remote repo, You have to run Clean build in eclipse, This will deploy the latest Library B to the maven repository
Also make sure your Library B version is a SnapShot during the development
If you are looking to run the latest snapshots on your local machine you should try to set things up to launch directly from Eclipse.
Apart from avoiding the problem you originally posted about, it also has other advantages.
It will save you a lot of time by not having to perform intermediate build steps.
You can start and stop servers without having to leave your IDE.
The Eclipse console has extra features that you don't get from the system console.
You don't have to modify your start scripts to attach a debugger.
I have a project (built from an AppFuse template) that requires Maven 2.2.1. So I upgraded to this (from 2.1.0) and set my path and my M2_HOME and MAVEN_HOME env variables.
Then I ran mvn eclipse:eclipseand imported the project into Eclipse (Galileo).
However, in the problems list for the project (and at the top of the pom.xml GUI editor) it says:
Unable to build project
'/export/people/clegg/data/Workspace/funcserve/pom.xml;
it requires Maven version 2.2.1
This persists whether I set Eclipse to use its Embedded Maven implementation, or the external 2.2.1 installation, in the Preferences -> Maven -> Installations dialog.
I've tried closing and reopening the project, reindexing the repository, cleaning the project, restarting the IDE, logging out and back in again, everything I can think of! But Eclipse still won't believe I have Maven 2.2.1.
I just did a plugin update so I have the latest version of Maven Integration for Eclipse -- 0.9.8.200905041414.
Does anyone know how to convince Eclipse I really do have the right version of Maven? It's like it's recorded the previous version somewhere else and won't pay any attention to my changes :-(
Eclipse allows you to specify an external Maven installation. But there's a catch. :(
Have a look at Windows > Preferences > Maven > Installations.
You will see a message like this:
Note: Embedded runtime is always used for dependency resolution, but does
not use global settings when it is used to launch Maven.
To learn more, visit the maven web page.
Translating to English, it means that Eclipse will continue to employ its internal Maven instance in order to perform some tasks.
When you "Run As > maven install" it will run your pom.xml script employing the external Maven instance you specified but when Eclipse performs some of its internal stuff, it will continue to use the embedded Maven instance, whatever version it is.
(edited)
As far as I know, when you install M2Eclipse you are implicitly defining which "internal Maven instance" you will have, which is exactly that one packaged by the plugin.
In the plugin configuration, you can add external Maven instances by telling where they are installed.
If you are using a recent m2eclipse version, you can try this too:
<prerequisites>
<maven>>=2.2.1</maven>
</prerequisites>
Notice the greater than in >=2.2.1. It works fine for me.
A common source of trouble (of this kind) is if you change global preferences and don't remember or know that you have enabled some project specific settings. At least it's a chance that the global setting is now set to use the external maven but the project setting is still set to 'embedded'.
M2Eclipse uses an embedded maven instance, not the maven instance you have installed on your system.
Have you tried switching workspaces?
You can still reference the same project in the new workspace. This would provide about as much of a reset as you can do in terms of eclipses internal settings.
Try creating your eclipse project with mvn project:m2eclipse or use the maven import option under import project.
Using m2eclipse, my fallback in these situations is to do Maven > Update Dependencies and then Maven > Update Project Configuration. The first is just me being supersticious, but the second will rewrite .project and .classpath.
As Pascal says about, m2eclipse can also be pointed at an external instance. I've done this in the past, though not at 2.2.1.
Dan
I got the same issue. Resolved it by restarting the system because every time you change the 'Path' in environment variables you should restart the system or else if would not pick the changes.