有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

gradle如何让我的密钥库文件与我的Java Vert一起工作。x项目(无效的密钥库格式)

我有一个Java Vert。x Gradle项目,我正试图得到Vert。x auth JWT使用它,但是当我运行我的项目时,我得到一个Invalid keystore format错误

我正试图在当地做到这一点;我使用的是iMac

以下是我的build.gradle文件的一部分:

构建。格拉德尔

// Import to replace ant-style tokens (@environmentVariable@) with values
import org.apache.tools.ant.filters.ReplaceTokens

buildscript {
  ext.vertxVersion = '3.5.4'
}

dependencies {
  compile "io.vertx:vertx-core:$vertxVersion"
  compile "io.vertx:vertx-web:$vertxVersion"
  compile "io.vertx:vertx-web-client:$vertxVersion"
  compile "io.vertx:vertx-web-templ-thymeleaf:3.5.4"
  compile "io.vertx:vertx-unit:$vertxVersion"
  compile 'io.vertx:vertx-auth-jwt:3.5.4'
  compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
  compile "org.slf4j:slf4j-api:1.7.25"
  testCompile group: 'junit', name: 'junit', version: '4.12'
  implementation 'com.google.code.gson:gson:2.8.5'
}

//Replace ant-style tokens with properties.
processResources {
    filter( ReplaceTokens, tokens:  properties )
}

下面是我如何在我的Vert中实现的。x垂直

主垂直线。爪哇

JWTAuthOptions config = new JWTAuthOptions();
config.setKeyStore(new KeyStoreOptions()
        .setType(Constants.KEY_STORE_TYPE) /* = "jceks" */
        .setPath(Constants.KEY_STORE_PATH) /* = "keystore.jceks" */
        .setPassword(Constants.AUTH_KEY_STORE_PASSWORD)); /* correct password */

JWTAuth provider = JWTAuth.create(vertx, config);

router.route(Constants.HOME_PAGE + "/*").handler(JWTAuthHandler.create(provider));

这里是我保存keystore.jceks文件的地方:

密钥库。jceks

My-Project
  |----src
        |----main
              |----resources
                      |----keystore.jceks

我首先与gradle一起构建我的项目:

$ ./gradlew clean build

构建我的项目效果很好。然后我尝试运行我的项目:

$ java -jar build/libs/MyProject-far-1.0.jar

当我运行项目时,出现以下错误:

java.lang.RuntimeException: java.io.IOException: Invalid keystore format
at io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl.<init>(JWTAuthProviderImpl.java:107)
at io.vertx.ext.auth.jwt.JWTAuth.create(JWTAuth.java:56)
at com.ucg.warehouselocationmapping.app.MainVerticle.start(MainVerticle.java:54)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:491)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:339)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)

我使用this作为如何实现Vert的参考。x auth JWT以及另一个项目的代码

我使用的keystore.jceks文件是从另一个项目复制的,在那里它工作得非常好。它首先是通过在Eclipse中拖动来复制的。当这不起作用时,我尝试在终端中复制它:

$ cp /Users/Me/workspace/My-Service/src/main/resources/keystore.jceks /Users/Me/workspace/My-Project/src/main/resources

这不起作用,所以我试着通过Finder复制它。那也没用

以前有人遇到过这个问题吗?我不太熟悉jks/jceks文件或身份验证

答案

import org.apache.tools.ant.filters.ReplaceTokens插件在我的keystore.jceks文件中查找@符号并对其进行操作,而我实际上只希望在属性文件中替换ant样式的标记。我更新了我的build.gradle文件,只替换以.properties结尾的文件,这解决了我的问题

//Replace ant-style tokens with properties.
processResources {
    filesMatching('**/*.properties') {
        filter( ReplaceTokens, tokens:  properties )
    }
}

共 (1) 个答案

  1. # 1 楼答案

    import org.apache.tools.ant.filters.ReplaceTokens插件在我的keystore.jceks文件中查找@符号并对其进行操作,而我实际上只希望在属性文件中替换ant样式的标记。我更新了我的build.gradle文件,只替换以.properties结尾的文件,这解决了我的问题

    //Replace ant-style tokens with properties.
    processResources {
        filesMatching('**/*.properties') {
            filter( ReplaceTokens, tokens:  properties )
        }
    }