您的位置:首页 > 其它

使用IDEA+MAVEN管理项目依赖

2008-03-27 10:30 513 查看
java jar文件太多了,管理起来很繁琐,是在每个项目下面放一个lib文件,还是所有项目公用一个lib呢?都麻烦

IDEA+MAVEN 试试看吧,

下载maven2

在IDEA项目根文件夹新建一pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>get_train_data</groupId>
<artifactId>get_train_data</artifactId>
<packaging>jar</packaging> 
<version>1.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testSourceDirectory>test</testSourceDirectory>
<testResources>
<testResource>
<directory>src/main/resources</directory>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>runjar</id>
<phase>install</phase>
<configuration>
<tasks>
<property name="compile-classpath" refid="maven.compile.classpath"/>
<property name="runtime-classpath" refid="maven.runtime.classpath"/>
<ant target="runjar" inheritRefs="true"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.3-603.jdbc3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate3</artifactId>
<version>3.2.3.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>hibernate-annotations</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>hibernate-commons-annotations</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>hibernate-entitymanager</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.1.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>hibernate-entitymanager</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.1_3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId> commons-collections</groupId>
<artifactId> commons-collections</artifactId>
<version>3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId> asm</groupId>
<artifactId> asm</artifactId>
<version>1.5.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.6</version>
<scope>compile</scope>
</dependency>

</dependencies>

</project>

建立一个ant 的 build.xml文件(我需要运行我的主类GetTrainData):

<project name="get_train_data_antrun" basedir="." default="runjar">
<path id="classpath">
<path path="${runtime-classpath}"/>
</path>
<target name="runjar">
<java classname="com.zeeeitch.GetTrainData" fork="true" maxmemory="512m">
<classpath>
<path refid="classpath"/>
<path location="get_train_data-1.0.jar"/>
</classpath>
</java>
</target>
</project>



点击刷新的图标,IDEA project的dispendency自动就改了,原先设置被覆盖了



点击install吧,直接就运行了。

说明一点,maven对文件夹结构的灵活性没有IDEA好,所以只有让IDEA稍稍修改一下文件夹结构,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: