Java Planet

O Javie i jej otoczeniu

Maven dependency scopes

Maven provides four dependency scopes:

  • compile: A compile-scope dependency is available in all phases. This is the default value.
  • provided: A provided dependency is used to compile the application, but will not be deployed. You would use this scope when you expect the JDK or application server to provide the JAR. The servlet APIs are a good example.
  • runtime: Runtime-scope dependencies are not needed for compilation, only for execution, such as JDBC (Java Database Connectivity) drivers.
  • test: Test-scope dependencies are needed only to compile and run tests (JUnit, for example).


Tyle teorii. Poniżej działający pom.xml  dala projektu ejb-module, będącego częścią aplikacji ear

  <dependencies>
	<dependency>
		<!-- dołączany do pliku ear -->
		<groupId>eu.swierczyna.prov</groupId>
		<artifactId>provisioning-core</artifactId>
		<version>[0.5.7,)</version>
		<scope>compile</scope>
	</dependency>
	<dependency>
		<groupId>log4j</groupId>
		<artifactId>log4j</artifactId>
		<version>1.2.15</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>toplink.essentials</groupId>
		<artifactId>toplink-essentials</artifactId>
		<version>2.1</version>
		<scope>provided</scope>
	</dependency>
        <dependency>
		<!-- konieczny tylko lokanie do kompilacji -->
		<groupId>org.apache.openejb</groupId>
		<artifactId>javaee-api</artifactId>
		<version>5.0-1</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<!-- konieczny tylko lokanie do testów JPQL -->
		<!-- teoretycznie powinien być runtime, ale z runtime nie chce działać -->
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.6</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<!-- konieczny tylko lokanie do jednostkowych -->
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>3.8.1</version>
		<scope>test</scope>
	</dependency>
 </dependencies>

A tutaj plik pom dla ear:

	<dependencies>
		<dependency>
			<groupId>eu.swierczyna.prov</groupId>
			<artifactId>IpManager-ejb</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>ejb</type>
			<scope>compile</scope>
		</dependency>
	</dependencies>

W przygotowanej paczce ear znajdziemy tylko te jary, które faktycznie są potrzebne

seba@latitude:~/workspace/IpManager/IpManager-ear$ zip-ls.py target/IpManager-ear-0.0.1-SNAPSHOT.ear
   69808  2010-03-06 11:57  IpManager-ejb-0.0.1-SNAPSHOT.jar
 4300323  2010-03-06 11:57  provisioning-core-0.5.8.jar
       0  2010-03-06 11:57  META-INF/
     123  2010-03-06 11:57  META-INF/MANIFEST.MF
     398  2010-03-06 11:57  META-INF/application.xml
       0  2010-03-06 11:57  META-INF/maven/
       0  2010-03-06 11:57  META-INF/maven/eu.swierczyna.prov/
       0  2010-03-06 11:57  META-INF/maven/eu.swierczyna.prov/IpManager-ear/
     121  2010-03-06 11:57  META-INF/maven/eu.swierczyna.prov/IpManager-ear/pom.properties
    2493  2010-01-25 15:44  META-INF/maven/eu.swierczyna.prov/IpManager-ear/pom.xml

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

COMMENTS

No Comments

There are no comments posted yet. Be the first one!

Leave a Replay