shwoseph
shwoseph

Reputation: 249

developing with maven

I've recently started working with this group doing java development. They use maven and svn to manage all of their code and I don't have any real experience with maven so I'm trying to play catch-up. From what I've seen, if you're going to modify one of their projects you check it out with svn, then mess with dependencies in pom.xml for 20 minutes, then you can build it using mvn install or whatever. We have an internal repository and all of the projects have a lot of dependencies to code in the repository, so I'm pretty much stuck using maven to build every time. Generating an eclipse project from maven isn't working because of the dependencies.

What's really frustrating me is that there doesn't seem to be a good way to run the code or debug it. Maven is producing jar files that can only be executed by maven because the manifest.mf file doesn't have the right path to the main function, etc. Java -jar won't work on them.

As far as debugging goes, I spent most of today on google trying to figure out a way to use eclipse to step through my code, but apparently that just can't be done. I was trying to setup kind of remote debugging with the surefire plugin, but you have to write unit tests for that or something which is way overkill for my purposes. In my previous java experience we used svn, ant, and eclipse which was much simpler.

Anyway, can somebody with a more experience give me some tips on developing with maven as a build tool? Asking my co-workers has been generally unhelpful. I feel like maven is probably a great tool that I just know next to nothing about and I just can't get anything done without being able to step-through and debug my code.

Upvotes: 4

Views: 156

Answers (2)

Nathaniel Waisbrot
Nathaniel Waisbrot

Reputation: 24473

Developing the Maven POM file can be complex if it's got a lot going on, but once it's been written it should be very easy to build and work with a project. It's troubling that your coworkers aren't able to explain to you how to work with a Maven-based project.

The m2e plugin is definitely the way to go if you're in Eclipse. You can single-step debug to your heart's content and you can mostly ignore that the project is Maven-based at all.

If you really want to build and work with jar files, I would use the maven-shade-plugin to build an über-jar file containing all the dependencies. (That's generally not the kind of thing you'd distribute, but when you just want a simple jar file for command-line work it's fantastic.) To use the shade plugin, you'd 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

Upvotes: 1

mantrid
mantrid

Reputation: 2840

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

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

Upvotes: 4

Related Questions