非常轻量级的Eclipse-Maven集成 - 仅依赖管理? [英] Very lightweight Eclipse-Maven integration - dependency management only?
问题描述
我想知道我是否能够提供非常简单和轻便的 Eclipse-Maven集成,仅提供仅添加Maven依赖关系以最简单的方法到Eclipse项目类路径。
特别是我不想:
- 适用于任何Maven约定(包括项目布局修改)
- 安装和使用任何特定的Eclipse插件(Eclipse不应该知道它是Maven项目,以任何特殊方式对待)
- 依靠/绑定到Maven以任何其他方式比使用它作为轻量级jars /库下载
我的第一个(也是唯一)的想法是使用 Eclipse Maven插件从命令行管理项目类路径。但默认情况下,这个插件比它更多(设置默认的maven项目布局,管理构建器)。我可以限制这个插件只做我想要的东西吗?
或者我可以达到我以其他方式描述的目标吗?
我发现一个非常适合我所描述的需求/用例的解决方案:
1。我在Eclipse项目根中创建了非常小的pom文件:
< 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>
<依赖关系>
<依赖关系>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.16< / version>
< / dependency>
< / dependencies>
< / project>
此.pom文件由三部分组成:
- 必需的Maven内容,即modelVersion和GAV
-
构建
部分,其中Maven默认的源和输出目录并覆盖以模仿Eclipse环境(这是对关于限制maven-eclipse-plugin行为的问题,其他一些eclipse:eclipse目标选项,如buildcommands
可能在一些更复杂的情况下有用) -
依赖关系
部分列出我需要在项目类路径上的依赖关系
2。从命令行我调用以下命令:
mvn eclipse:configure-workspace -Declipse.workspace = C:/ myworkspace
cd C:/ myworkspace / myproject
mvn eclipse:eclipse
3。每次我想从Maven文件中更新Eclipse项目类路径时,我可以执行以下两项操作之一:
- 从命令行调用最后两行
- bind mvn eclipse:eclipse到Eclipse 外部工具配置,并单击
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?
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 likebuildcommands
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
这篇关于非常轻量级的Eclipse-Maven集成 - 仅依赖管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!