Very lightweight Eclipse-Maven integration - dependency management only?

限于喜欢 提交于 2019-12-19 10:26:46

问题


From my experience, Maven is often an overkill in small/experimental applications. But depencency management is very useful feature of Maven and actually the only one that can be really helpful in mentioned type of applications.

I wonder if I can have a very minimal and lightweight Eclipse-Maven integration that provides only adding Maven dependencies to Eclipse project classpath in the simpliest possible way.

Especially I don't want to:

  • apply to any Maven conventions (including project layout conventons)
  • install and use any specific Eclipse plugins (Eclipse shouldn't know at all that it is "Maven project" and treat it in any special way)
  • depend on/be bound to Maven in any other way than using it as lightweight jars/libraries downloader

My first (and only) idea is to use Eclipse Maven plugin from command line to manage project classpath. But by default this plugin does more than it (sets up default maven project layout, manage builders). Can I limit this plugin to only do what I want?

Or can I reach the goals I described in any other way?


回答1:


I found a solution that fits very well to needs/use case that I described in question:

1. I created very minimal pom file in Eclipse project root:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sobczyk.piotr</groupId>
    <artifactId>mvn-eclipse-test</artifactId>
    <version>1.0.0</version>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <outputDirectory>bin</outputDirectory>
    </build>

    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
    </dependencies>
</project>

This .pom file consists of three parts:

  • Required Maven stuff, ie. modelVersion and GAV
  • build section where Maven default source and output directories and overriden to mimic Eclipse environment (it's the answer to the part of question on limiting maven-eclipse-plugin behaviour, some other eclipse:eclipse goal options like buildcommands may be useful in some more complex cases)
  • dependencies section listing dependencies that I need to have on project classpath

2. From command line I invoked following commands:

mvn eclipse:configure-workspace -Declipse.workspace=C:/myworkspace
cd C:/myworkspace/myproject
mvn eclipse:eclipse

3. Each time I want to update Eclipse project classpath from Maven file I can do one of two things:

  • invoke last two lines from command line
  • bind mvn eclipse:eclipse to Eclipse external tool configuration and invoke it with single click



回答2:


Sorry, there's not. As you can see here:

http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html

the configuration of the plugin allows to add some additional classppath items, facelets etc. but you can't skip the default ones.



来源:https://stackoverflow.com/questions/10122614/very-lightweight-eclipse-maven-integration-dependency-management-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!