java 在 maven 项目中为 j2ee.jar 添加依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7984555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add dependency in maven project for j2ee.jar
提问by arsenal
What is the maven dependency for j2ee.jar. I tried doing this way. But still its not working..
j2ee.jar 的 maven 依赖是什么。我试过这样做。但它仍然不起作用..
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.datasource.pooling</groupId>
<artifactId>datasource.pooling</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>com.datasource.pooling</name>
<repositories>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<dependencies>
<!-- Javaee API -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<!--
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.3</version>
</dependency>
-->
</dependencies>
</project>
I am trying to configure this http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/doc/PoolingDriverExample??.java?view=markup example in my maven project. So in that I have to add j2ee.jar into my classpath. But If I am adding by above in my pom.xml then I am getting some error as ConnectionFactory cannot be resolved to a type
我正在尝试在我的 maven 项目中配置这个http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/doc/PoolingDriverExample??.java?view=markup 示例。因此,我必须将 j2ee.jar 添加到我的类路径中。但是如果我在 pom.xml 中添加了上面的内容,那么我会收到一些错误,因为 ConnectionFactory 无法解析为类型
Update-
更新-
<!-- Javaee API -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>runtime</scope>
</dependency>
still I am getting the same error for ConnectionFactory cannot be resolved to a type..
我仍然收到相同的错误,因为 ConnectionFactory 无法解析为类型..
采纳答案by user620339
You can check for transitive dependencies using the maven dependency plugin. Just do an
您可以使用 maven 依赖插件检查传递依赖。做一个
mvn dependency:tree
Hope this answers your question.
希望这能回答你的问题。
回答by green reign
The repo you specified does not provide that version:6.0
您指定的回购不提供该版本:6.0
The repo you specified has http://download.java.net/maven/glassfish/javax/javaee/javaee/
您指定的回购有http://download.java.net/maven/glassfish/javax/javaee/javaee/
- 5.0-SNAPSHOT/ 14-Feb-2008 15:04 1K
- 6.0-alpha-1/ 16-Apr-2008 17:36 1K
- 6.0-alpha-2-SNAPSHOT/ 23-Apr-2008 08:31 1K
- 5.0-快照/ 2008 年 2 月 14 日 15:04 1K
- 6.0-alpha-1/ 2008 年 4 月 16 日 17:36 1K
- 6.0-alpha-2-SNAPSHOT/23-Apr-2008 08:31 1K
You may want to use http://repo1.maven.org/maven2which does provide the resource and version you specified.
您可能希望使用http://repo1.maven.org/maven2,它确实提供了您指定的资源和版本。
Also, your scope should be "provided". Having a runtime scope tells maven that the dependency is needed for runtime but not compilation. You need the opposite. Your dependency is needed for compilation but not runtime because it's "provided" by the container. See http://maven.apache.org/pom.htmlfor more details.
此外,您的范围应该是“提供”的。拥有运行时范围告诉 Maven 运行时需要依赖项,但不需要编译。你需要相反的。编译需要依赖项,但运行时不需要依赖项,因为它是由容器“提供”的。有关更多详细信息,请参阅http://maven.apache.org/pom.html。