Development with maven

I recently started working with this java development team. They use maven and svn to manage all their code, and I have no real experience with maven, so I try to play catch-up. From what I saw, if you are going to change one of your projects, you check it with svn and then mess with dependencies in pom.xml for 20 minutes, then you can build it using mvn install or something yet. We have an internal repository, and all projects have many dependencies for the code in the repository, so I was practically stuck using maven to build every time. Creating an eclipse project from maven does not work due to dependencies.

What really upsets me is that there seems to be no good way to run the code or debug it. Maven creates jar files that can only be executed by maven, because the manifest.mf file does not have the correct path to the main function, etc. Java-jar will not work on them.

As for debugging, I spent most of today's day at Google trying to figure out how to use eclipse to navigate through my code, but apparently this just can't be done. I tried to configure remote debugging using the surefire plugin, but you need to write unit tests for this or something that is too complicated for my purposes. In my previous java experience, we used svn, ant and eclipse, which were much simpler.

Anyway, can anyone with more experience give me some development tips using maven as a build tool? Asking my staff was generally useless. I feel that maven is probably a great tool that I just don’t know anything about, and I just can’t do anything without executing and debugging my code.

+4
source share
2 answers

when developing maven projects with Eclipse, use the m2e plugin - or install it directly from the Eclipse Marketplace (i.e. through the menu)

it will automatically handle dependencies, build paths, class paths, environment settings, etc. - here you can learn more about it

+3
source

Developing a Maven POM file can be difficult if it goes through a lot, but once it is written, it is very easy to create and work with the project. This worries that your colleagues cannot explain to you how to work with a Maven-based project.

The m2e plugin is definitely suitable if you are in Eclipse. You can do one-step debugging to your heartfelt content, and you can basically ignore that the project is generally based on Maven.

If you really want to create and work with jar files, I would use the maven-shade-plugin to create a über-jar file containing all the dependencies. (This is usually not what you distribute, but when you just need a simple jar file for the command line, this is fantastic.) To use the hue plugin, you must add this to the <plugins> section of your POM:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.6</version> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>you.main.class.GoesHere</mainClass> </transformer> </transformers> </configuration> <executions> <execution> <phase>package</phase> <goals><goal>shade</goal></goals> </execution> </executions> </plugin> 

And then run

  mvn package 

on the command line

0
source

Source: https://habr.com/ru/post/1469116/


All Articles