Maven ojdbc jar依赖项错误:包oracle.jdbc不存在
回答:
我试图在我的Java EE6应用程序(类名VisualizerRepository.java)中使用jdbc连接,但是在nexus存储库中有jdbc驱动程序
该类必须执行存储过程并打印该过程的结果。由于JPA 2.0不支持使用jdbc调用程序。
包com.nfsmith.crm.data.repository;
import java.sql.CallableStatement;import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import oracle.jdbc.OracleTypes;
import org.jboss.logging.Logger;
@Named
@ApplicationScoped
public class VisualizerRepository
{
DataSource datasource;
Connection connection;
CallableStatement statement;
@PostConstruct
public void initDBConnection()
{
InitialContext context;
try
{
context = new InitialContext();
datasource = (DataSource) context.lookup("java:jboss/datasources/partmatchDatasource");
connection = null;
statement = null;
connection = datasource.getConnection();
}
catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getJSonDataList()
{
try {
statement = connection.prepareCall("{call crm.PKG_CRM_RELATIONSHIP.getOrgViewDataJason(?,?,?)}");
int owner = 48156;
statement.setInt(1, owner);
int site = 10;
statement.setInt(2, site);
statement.registerOutParameter(3, OracleTypes.CURSOR);
statement.execute();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
statement.close();
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
当我执行构建时,看到编译错误,提示软件包oracle.jdbc不存在,无法找到符号
[ERROR] COMPILATION ERROR : [INFO] -------------------------------------------------------------
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[15,19] package oracle.jdbc does not exist
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[66,51] cannot find symbol
symbol: variable OracleTypes
location: class com.nfsmith.crm.data.repository.VisualizerRepository
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Smith CRM ......................................... SUCCESS [0.823s]
[INFO] Smith CRM Web ..................................... FAILURE [4.775s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.410s
[INFO] Finished at: Wed Aug 07 13:48:32 CDT 2013
[INFO] Final Memory: 36M/530M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "CRM_local" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project smith-crm-web: Compilation failure: Compilation failure:
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[15,19] package oracle.jdbc does not exist
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[66,51] cannot find symbol
[ERROR] symbol: variable OracleTypes
[ERROR] location: class com.nfsmith.crm.data.repository.VisualizerRepository
[ERROR] -> [Help 1]
回答:
ojdbc jar不在公共Maven存储库中。您可以手动将jar添加到本地存储库。
- 甲骨文网站
- 从您的oracle数据库服务器复制( )
mvn install:install-file -Dfile={Path/to/your/ojdbc.jar} -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
以上是 Maven ojdbc jar依赖项错误:包oracle.jdbc不存在 的全部内容, 来源链接: utcz.com/qa/414961.html