Making Eclipse Maven repository inside the project - eclipse

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.

Related

JBoss 6.1.1.EAP Module Deployment: Class not found

The structure is as follows:
Actually deployed module is EAR.
EAR contains WAR module, and WAR module contains another JAR module.
In this last JAR, there are some generated classes and their parent folder is also used as source folder. Its path is "target/generated-sources/java".
The problem that is killing me, is that the deployed application throws ClassNotFoundException on server start, and the classes in question are the generated ones.
Now the trick:
if I explicitly change the Deployment Assembly in WAR project in Eclipse not to contain JAR project as "project", but as an archive from the JAR's project "target" folder, JBoss sees the generated classes and starts.
This solution however works only until next eclipse maven project update, so manual edit of deployment assembly is not really a solution.
Any ideas how to deploy or reorganise packages correctly?
OK, seems I have found the solution.
I looked through the build-path of the mentioned JAR file and saw that the entry Output folder pointed to target/test-classes.
After changing this entry to target/classes the application deploys and starts without any missing generated classes.
This is what worked for me:
Expand the 'target' folder of your maven project inside Eclipse (Project Explorer View);
Refresh it (F5);
Right click on your project on 'Servers' tab, then select "Full Publish";
Start your JBoss.
I had to enforce the JBoss Tool "Full Publish" to get an updated version of my target folder by Refreshing it manually on eclipse.
I don't know why but sometimes the Publishing from maven projects (even Full Publishes) do not copy classes from the target Project as it is in the file system. Maybe it's using some outdated memory info or some cache...
Anyway, this is what works for me.
After an update to Eclipse 4.15 and JBoss tools I got this problem too.
My solution: project -> properties -> Java Build Path --> Source
There my Output folder from my source was linked to project/target/classes, I changed this to project/target/project-projectversion/WEB-INF/classes
When I looked into the standalone JBoss folder I saw the folder structure of my source, but the classes where missing, when I changed the output folder the classes pop up and everything worked like before.
I am pretty sure the update made the problems.

Adding jars to Tomcat classpath

I have an Eclipse project running on Tomcat, with my dependency jars sitting in the WEB-INF/lib directory. Everything is great. But the war file created on export is huge, and I'm going to need to send it back and forth to the test server, which will be time consuming. It seems like a waste.
So I put all my dependency jars in a folder, dependency_jars, in my file system, and configured the build to point there. The build works, but when I run it (still on my local machine) the app is throwing runtime errors.
Reading around, I went to the project properties and added the jars to the Web Deployment Assembly. Now the runtime works, but the exported war once again has all the jars packaged with it.
So how do I have my dependencies available for the runtime environment, without having Eclipse package them inside the war?
OK I'm not sure this is the most elegant solution but what I did is configure Tomcat to use an external library, put the dependency jars there, and then let eclipse create the war with everything in it, explode it from the command line, remove the dependency jars, repackage the war, and finally send it out.
Well, definitely not an elegant solution. But it works. Here are the steps:
Configure Tomcat to use an external resources library. Go to tomcat_home/conf/catalina.properties and add your directory under the comment that starts with "List of comma-separated paths defining the contents of the "common" classloader..."
Export war through Eclipse.
Explode the war (pun probably merited here:) jar -xvf MyWar.war
Remove your dependency jars (which are now in the external directory from step 1 above.)
Repackage the war: jar cvf MyWar.war WEB-INF

Where do Maven look for springMVC jars when working with eclipse(maven plugin installed)

I am using m2e plugin.
Just stuck at one point when maven search for springMVC jar files where it would be searching.
In /web-inf/lib or in project build path.
Where should I put those jars
Thanks
Maven looks for jars in its repositories.
Therefore you don't need download jars manually when using Maven, it will automatically download jars from remote repository and put it to the local repository on your machine.
Maven uses "settings.xml" file to find out your project repositories. and resolve dependencies(every jar files that you need) from those repositories.
more about seetings.xml and also
this one .
After downloading required jar file for first time, maven puts it in your local repository in:
${user-home}/.m2/repository.

JAR File is Viewed as Folder

I have a JAR-file in the WEB-INF/lib directory of my project that is displayed as folder when I deploy my project to Tomcat.
I use Maven for getting JAR-files, Eclipse for building my app, and deploying to Tomcat.
Why is the JAR-file displayed as folder? I cannot use the file in this way, and Tomcat does not see it.
This settings is for any child module if we have one parent maven project for him and we want to use wtp.
Eclipse gets changes from workspace.
For Example, we make changes in maven module and we don't need to install it and update dependencies for parent. Eclipse automatically updates the changes.
Because if you use Eclipse Web Tools Platform for deploying, it puts artifacts, that you have in your Eclipse workspace as projects, exploded. It allows WTP to do some magic with replacing classes files in-place instead of repackaging whole artifact on every little change. For the container, it really doesn't matter.

ClassNotFoundException when using User Libraries in Eclipse build path

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.