Eclipse maven ear project deployment - eclipse

I have a modular maven project.
On the top level I've got:
<modules>
<module>base</module>
<module>module1</module>
<module>module2</module>
<module>ear</module>
</modules>
The base module gets packed as a jar. module1 and module2 as war with a dependency on the base module. The Ear project has dependencies upon module1 and module2 and packages them accordingly. The pom's of module1 and module2 are exactly the same!!
Everything works perfect, except the deployment to the local server from eclipse. The problem is that module2 is missing base.jar in the lib folder of the deployed ear. Yet, module1 has it! If I run a mvn install from the command line it's also included in the target lib folder! In eclipse, all dependencies are resolved!
I've tried everything I can think of:
reimporting the projects,
cleaning all eclipse related files,
cleaning the local maven repository,
cleaning the servers tmp folder and re-add the projects,
do a maven update and install
Nothing helped so far.
Cheers
Edit:
I have made a somehow horrifying discovery:
I've added a module named "amodule". Guess what, it got the required jar and the others didn't. It seems like only the alphabetical first module gets the jar and the others don't.

My solution was to uncheck "resolve workspace dependencies" in the projects that include the base module. (project -> preferences -> maven -> uncheck: resolve workspace dependencies)
It comes with a side effect though: During debugging, the base.jar is handled like an external jar in the module. It is possible to specify the source code path, but I can't set a break point in the base project and wait until the debugger hits that line.

Related

Maven Eclipse Plugin Doesn't Create Project Dependencies Properly

Suppose I have a top level maven project with two modules:
moduleA
moduleB
and a groupId of my.group.
running mvn eclipse:eclipse on the parent project should generate eclipse files for all subprojects. The issue with this is that it doesn't include the groupId by default and only uses the artifactId.
So:
mvn eclipse:eclipse -Declipse.projectNameTemplate=[groupId].[artifactId]
This includes the group id in the project name, which is what the default behaviour should have been to begin with. Now the projects are named correctly in the .project files (my.group.moduleA, my.group.moduleB), but the .classpath files are all screwed up because they are still only using the artifactId and trying to reference projects moduleA and moduleB.
Am I missing something here or is this a bug in the maven eclipse plugin? It seems like a name change should propagate to everywhere the name is used. I.e. It should reference the project dependencies correctly and not require a bunch of manual classpath fixes inside eclipse that will get overwritten the next time mvn eclipse:eclipse is run.
The <name> element of the .project file gets set correctly, but it's using the wrong names in both the .classpath file and <projects> section of the .project file.
MVN Version: 3.2.5
The maven-eclipse-plugin is nowadays considered as abandonned. You better have to simply import your raw projects direcly from Eclipse (with m2eclipse installed) as Maven projects. Then the setup should be done properly.

Making Eclipse Maven repository inside the project

I'm a real beginner to Maven and Spring framework in eclipse so excuse me if this sounds trivial..
I have created a MVC web project in eclipse using the STS plugin on my windows computer, but my problem is that the location of the jar and configuration files that maven is set to by default is: C:\Users\MyName.m2\repository
This is a problem for me because eventually I'm going to make a WAR file out of my project and deploy it on a Linux machine, which does not have Maven installed on it.
My question is, is it possible to take all the jar files in my Maven repository, and make a local repository on the project itself rather than on an absolute path on the machine (sort of like a lib folder within the WEB-INF in the project that will hold all the maven jars and that maven will direct itself to it), and thus making the transition to the Linux machine smooth
I understand there is this classpath variable named M2_REPO, but doesn't seem to be editable or accept relative path rather than absolute.
Thanks in advance
Since you are using maven and you are adding your dependencies on your pom.xml, then all the dependencies with a scope of "compile" will be added to your final war file created by the maven war plugin under the WEB-INF/lib folder, this means that you should not worried about having maven in your linux server, since the war file that you are going to deploy will contain all the necessary dependencies. If you want to confirm this, just create a package of your project using "mvn clean package" and check the "target" folder generated by maven, you will see a "war" file, and you can unzip your file to check what contains.

Project compiles fine in IntelliJ, Tomcat says java.lang.NoClassDefFoundError: my/package/name/blah

My project compiles fine in IntelliJ, it is a simple spring-mvc written in scala.
I get this error when I run it using tomcat:
java.lang.NoClassDefFoundError: org/example/houses/SomeClassNameHere
The above isn't the exact name of my library.
My controller looks like:
package com.example.scalacms.web.controllers
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{ResponseBody, RequestMapping}
import org.example.house
#Controller
class HomeController {
var houses: Houses = _
#RequestMapping(Array("/"))
#ResponseBody
def index: String = {
"hello, world!"
}
}
I'm confused because it compiles fine in IntelliJ, it picks up all my classes in intellisense etc.
Could it be that tomcat doesn't have the library in my classpath? I am using an exploded artifact.
I can't see the classpath anywhere in the output windows so I cannot confirm.
Update
So I looked in the /out/artifacts/myapp_web_war_exploded/WEB-INF/lib and I don't see the jar file there. Why is the jar not being included in the deployment? What should I do to have it included in intellij?
If it's a maven WAR project, check if the jar is marked as excluded or in scope provided in the pom, as any of those would remove the jar from the WAR.
If it's not the case, go to the command line to the directory where the pom WAR is, and do a mvn dependency:tree and confirm that your jar is indeed there.
If the jar is there, then it means it can only be an IDE related problem. Try the following steps:
scrap your current server
download and unzip a clean server from the official site
configure the new server in the IDE
make sure to import the module as a maven module, so that IDEA builds both the compilation and the deployment classpaths fully based on the poms
If it's already a Maven project, click Maven Projects (hidden pane on the top left) and click Reimport All Maven Projects
do a Build -> Rebuild Project
Click F4 / Libraries and confirm the library is there, then run the server
i dont know in intellij but in eclipse when you deploy and work with maven it sometimes occurs that you not include your maven dependencies in your deployment assembly
look this :Maven dependencies not visible in WEB-INF/lib
I had the same problem and fixed it now after debugging ...
IntelliJ usually auto-creates a folder /lib under your /src folder inside your project, and then it would tell your project that all LIBs are in there, on that basis; we usually assume that it's the place to put all your LIBs in there as well.
Although with that setup your project would compile fine since IntelliJ can link up to your JARs However, with that sort of setup Tomcat will fail to execute, since Tomcat expects to find the classes under /WEB-INF/lib,...
Therefore, the solution is to:
1) Drag your LIB folder (sorry I mean "/lib") from /src/lib to be
under /web/WEB-INF directory
2) You would get a warning about moving classes / JARs, say YES.
(You need to tell your project to re-map your existing pre-defined
LIBs to the new folder):
3) From the main menu, select FILE -> Project Structure
4) Select
Libraries from the left menu
5) If you don't see any existing libs, then you're done, click OK
6) If you do see libs in there, then:
7) Click on each LIB from the
middle-list, and then remove the ones that can't be located,
8) Re-add them again from the new location
9) Repeat (7) to all other LIBs.
10) OK,
RE-compile, your project should deploy on Tomcat now and work fine.
Regards
Heider

Eclipse adding the project overrides maven dependency

I have a maven project that uses other small projects. And I added them to master's pom file.
So my Eclipse project properties looks like following:
>Master project
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1.jar
>smallProj2.jar
The thing is I do not have the all code for smallProj1 and smallProj2 and whenever add them to my workspace Eclipse overrides the maven dependencies and simply calls the two projects instead the jar files from my local maven repository and then I have all over the code those red underlines. Project properties in Eclipse looks as following after I add them to my workspace:
>Master project
>smallProj1
>smallProj2
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1 (not jar anymore - folder)
>smallProj2 (not jar anymore - folder)
Since I also want to have a look to smallProj1 and smallProj2 code while I am coding, I want to keep them both in my workspace. But I want my Master project to use the jar files that I provided, not the small projects in the workspace.
Any ideas on that?
You could right click on a project and set "Maven" -> "Disable Workspace Resolution". This will let Maven find the dependencies from Maven and not within the workspace. I don't think it is possible to do this on a dependency basis.
But I think in your case it would be better to fix the broken smallProjX in your workspace (as they exactly contain the code you need), so that the master project could be build correctly.

IvyDE Resolve Dependencies in workspace with a Dynamic Web project in Eclipse

I have a large application with many eclipse (actually using Spring Source Toolsuite) projects with ivy managed dependencies for each project. We currently have it setup and working where you can have project A (a dynamic web project that generates a war) and project B (generates a jar) setup such that project A depends on project B and if you only have project A in your workspace, it will go pull the jar file generated by project B from the ivy repository. We setup the deployment assembly to take the eclipse library generated from the ivy resolve and put it in the WEB-INF/lib directory so we can easily deploy to tomcat.
With the manual process, all of this works. I can make a change to project B, publish it to my local ivy repository, and re-resolve the dependencies on project A, and I get the new project B jar file and everything compiles and updates on tomcat as expected.
The problem I'm having comes when I change the ivy resolve settings of project A to "Resolve dependencies in workspace". When I make changes in project B, project A successfully notices the change and compiles correctly, but the deployment assembly breaks. When I go look in tomcat, it has a folder for project A's context root, but it is empty. If I uncheck the "Resolve dependencies in workspace" checkbox, the context root folder gets populated and everything returns to a working state.
I can continue doing the manual process, but it is a huge timesavings if I can get ivy to use my workspace first, then get the jar from the repository if the project does not exist in my workspace. Any suggestions would be greatly appreciated!
The solution was to add the Utility Module facet to project B (Project Properties->Project Facets->Utility Module) so that eclipse would know the structure of the jar file that is supposed to be generated.