2016-11-21 173 views
0

我正在嘗試連接到數據庫以啓動基準用戶身份驗證程序。我能夠使用shiro.ini來獲取用戶角色,但是在嘗試使用JDBC連接運行程序時出現錯誤。我曾嘗試同時使用Microsoft sqljdbc42.jar和jTDS jar文件,結果沒有任何區別。無論哪種方式,我得到以下錯誤:Apache Shiro JDBC連接問題

[ERROR] No plugin found for prefix 'java' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\mainuser.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]

我見過一對夫婦爲「找到的前綴無插件」,但沒有爲「Java」作爲不同的故障排除問題,所以我在一個頭緒繼續。

這裏是我的Shiro.ini文件,使用JTDS罐子:

[main] 
ds = net.sourceforge.jtds.jdbcx.JtdsDataSource 
ds.serverName = SQL5 
ds.user = myUser 
ds.password = myPassword 
ds.databaseName = myDatabase 

jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm 
jdbcRealm.dataSource = $ds 
jdbcRealm.permissionsLookupEnabled = true 
jdbcRealm.authenticationQuery = "SELECT pswd FROM Users  WHERE user = ?" 
jdbcRealm.userRolesQuery = "SELECT role FROM Role WHERE user = jdbcRealm.permissionsQuery = "SELECT perm FROM Person WHERE user = ?" 

這裏是我的pom.xml文件,使用JTDS罐子:

<?xml version="1.0" encoding="UTF-8"?> 
<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>org.apache.shiro.tutorials</groupId> 
<artifactId>shiro-tutorial</artifactId> 
<version>1.0.0-SNAPSHOT</version> 
<name>First Apache Shiro Application</name> 
<packaging>jar</packaging> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.0.2</version> 
      <configuration> 
       <source>1.5</source> 
       <target>1.5</target> 
       <encoding>${project.build.sourceEncoding}</encoding> 
      </configuration> 
     </plugin> 

    <!-- This plugin is only to test run our little application. It is not 
     needed in most Shiro-enabled applications: --> 
       <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.1</version> 
    </plugin> 
    </plugins> 
</build> 

<dependencies> 
    <dependency> 
     <groupId>net.sourceforge.jtds</groupId> 
     <artifactId>jtds</artifactId> 
     <version>1.3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.shiro</groupId> 
     <artifactId>shiro-core</artifactId> 
     <version>1.1.0</version> 
    </dependency> 
    <!-- Shiro uses SLF4J for logging. We'll use the 'simple' binding 
     in this example app. See http://www.slf4j.org for more info. --> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-simple</artifactId> 
     <version>1.6.1</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

回答

1

前綴對於exec-maven-pluginexec,因此您可以使用:mvn exec:java。但請注意,您還必須設置mainClass以允許此操作。

+0

我一直在使用mvn exec:java來運行我的代碼。當我不使用JDBC連接時它工作正常,我從[main]中錯過了什麼? –

+0

我不能相信我犯了這個錯誤,但我只是意識到我現在使用mvn java:exec而不是mvn exec:java。我現在感覺很傻。 –