我有点困惑.我无法在任何地方找到答案;(
我有一个String数组:
String[] arr = ["1", "2", "3"];
Run Code Online (Sandbox Code Playgroud)
然后我将它转换为字符串:
String str = Arrays.toString(arr);
System.out.println(str);
Run Code Online (Sandbox Code Playgroud)
我期望得到字符串"123",但我得到了字符串"[1,2,3]".
我怎么能在java中做到这一点?我正在使用Eclipse IDE
大家好,感谢您的关注!我有一个既容易又明显的问题,但我被卡住了.
我想通过自定义ClassLoader提供动态创建的Java类,供第三方库使用.
现在我的问题是:当我不自己直接加载这些类时,如何设置我的自定义ClassLoader来加载这些类?
我想当我使用我的ClassLoader加载某个类时,它就变成了这个类的ClassLoader,并且从该类加载的所有类都将通过我的ClassLoader引导.
我按照这个官方教程创建了一个自定义的ClassLoader:http://java.sun.com/developer/onlineTraining/Security/Fundamentals/magercises/ClassLoader/help.html.
public class DynamicClassloader extends ClassLoader {
private Map<String, Class<?>> classesMap = new HashMap<String, Class<?>>();
public DynamicClassloader(ClassLoader parent) {
// Also tried super(parent);
super(sun.misc.Launcher.getLauncher().getClassLoader());
}
// Adding dynamically created classes
public void defineClass(String name, Class<?> clazz) {
classesMap.put(name, clazz);
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
// load from parent
Class<?> result = findLoadedClass(name);
if (result != null) {
return result;
}
try {
result = findSystemClass(name);
} catch (Exception …Run Code Online (Sandbox Code Playgroud) 正如标题所述,我想知道如何修改它gradle.build.kts以便创建一个独特jar的所有依赖项(包括kotlin lib)的任务.
我在Groovy中找到了这个示例:
//create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.mkyong.DateUtils'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在kotlin中写出来,除了:
task("fatJar") {
}
Run Code Online (Sandbox Code Playgroud) 我在项目pom.xml中添加了jetty mvn插件代码.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<contextPath>/redkites</contextPath>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我使用命令sudo mvn compile和sudo mvn clean install,我没有发现任何错误和成功建立,但是当我键入命令sudo mvn jetty:run,我得到一个错误:
[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/root/.m2/repository), central (http://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with …Run Code Online (Sandbox Code Playgroud) 以下是我的用例:我有一个带有散列+范围键的Dynamo表.当我在表中放入新项目时,我想进行唯一性检查.有时我想保证散列是唯一的(忽略范围).其他时候我想允许重复哈希,但保证哈希和范围组合是唯一的.我怎么能做到这一点?
我尝试了attribute_not_exists.它似乎处理第二种情况,它检查哈希+键组合.这是一个PHP示例:
$client->putItem(array(
'TableName' => 'test',
'Item' => array(
'hash' => array('S' => 'abcdefg'),
'range' => array('S' => 'some other value'),
'whatever' => array('N' => 233)
),
'ConditionExpression' => 'attribute_not_exists(hash)'
));
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我使用attribute_not_exists(hash)或者似乎并不重要attribute_not_exists(range).他们似乎都做了完全相同的事情.这是它应该如何工作?
知道如何处理我只想检查hash唯一性的情况吗?
目标
在同一节点上运行声明性Jenkins管道的多个阶段.
设置
这只是一个显示问题的最小示例.有2个Windows节点"windows-slave1"和"windows-slave2"都标有"windows"标签.
注意:我真正的Jenkinsfile不能使用全局代理,因为有一些阶段需要在不同的节点上运行(例如Windows与Linux).
预期行为
Jenkins根据标签选择"Stage 1"中的一个节点,并在"Stage 2"中使用相同的节点,因为变量windowsNode已更新为"Stage 1"中选择的节点.
实际行为
"阶段2"有时在与"阶段1"相同的节点上运行,有时在不同的节点上运行.请参阅下面的输出.
Jenkinsfile
#!groovy
windowsNode = 'windows'
pipeline {
agent none
stages {
stage('Stage 1') {
agent {
label windowsNode
}
steps {
script {
// all subsequent steps should be run on the same windows node
windowsNode = NODE_NAME
}
echo "windowsNode: $windowsNode, NODE_NAME: $NODE_NAME"
}
}
stage('Stage 2') {
agent {
label windowsNode
}
steps {
echo "windowsNode: $windowsNode, NODE_NAME: $NODE_NAME"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
产量 …
嗨,我在运行JaCoCo报道时遇到以下异常:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.8.201207111220</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Error while creating report: Can't add different class with same name: org/hamcrest/BaseDescription
java.lang.IllegalStateException: Can't add different class with same name: org/hamcrest/BaseDescription
at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:89)
at org.jacoco.core.analysis.Analyzer$1.visitEnd(Analyzer.java:79)
at org.objectweb.asm.ClassAdapter.visitEnd(Unknown Source)
at org.jacoco.core.internal.flow.ClassProbesAdapter.visitEnd(ClassProbesAdapter.java:128)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:94)
at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:115)
at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:155)
at org.jacoco.core.analysis.Analyzer.analyzeArchive(Analyzer.java:135)
at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:158)
at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:183)
at org.jacoco.maven.ReportMojo.createBundle(ReportMojo.java:280)
at org.jacoco.maven.ReportMojo.createReport(ReportMojo.java:256)
at org.jacoco.maven.ReportMojo.executeReport(ReportMojo.java:230)
at org.jacoco.maven.ReportMojo.execute(ReportMojo.java:208)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) …Run Code Online (Sandbox Code Playgroud) 尝试编写一个使用RegEx来验证项目值的JSON模式.
有一个名为progBinaryName的项目,其值应该与此RegEx字符串相同"^[A-Za-z0-9 -_]+_Prog\\.(exe|EXE)$".
找不到任何实际解释在JSON模式中使用RegEx的教程或示例.
任何帮助/信息将非常感谢!
感谢:D
JSON SCHEMA
{
"name": "string",
"properties": {
"progName": {
"type": "string",
"description": "Program Name",
"required": true
},
"ID": {
"type": "string",
"description": "Identifier",
"required": true
},
"progVer": {
"type": "string",
"description": "Version number",
"required": true
},
"progBinaryName": {
"type": "string",
"description": "Actual name of binary",
"patternProperties": {
"progBinaryName": "^[A-Za-z0-9 -_]+_Prog\\.(exe|EXE)$"
},
"required": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
警告!更好地检查你的JSON.
实例不是必需的类型 - http://json-schema.org/draft-03/hyper-schema#
架构是有效的JSON,但不是有效的架构.
验证结果:失败
[ {
"level" : "warning",
"schema" : …Run Code Online (Sandbox Code Playgroud) 我在java类中遇到解密错误:
javax.crypto.IllegalBlockSizeException :
Input length must be multiple of 16 when decrypting with padded cipher.
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个问题?
更新:
我忘了提到它工作一次,当第二次我试图再次执行它时抛出上述错误.
package com.tb.module.service;
import java.security.Key;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.*;
/**
* This class is used for encrypt and decrypt the password field.
*
*/
public class PswdEnc {
private static final String ALGO = "AES";
private static final byte[] keyValue = new byte[] { 'T', 'h', 'e', 'B', 'e', 's', 't','S', 'e', 'c', 'r','e', 't', 'K', 'e', 'y' }; …Run Code Online (Sandbox Code Playgroud) 我@NonCPS在我的Jenkinsfile函数前面使用它执行正则表达式匹配,java.io.NotSerializableException java.util.regex.Matcher即使使用@NonCPS注释我仍然会收到错误.
注意,它多次调用该函数,只有在实际匹配时才会发生异常.
这是我的代码:
@NonCPS
def extractEndTime(logLine) {
def MY_REGEX = /.*(20[0-9]{2}-[0-9]{2}-[0-9]{2}).([0-9]{2}:[0-9]{2}:[0-9]{2}).*\"\w+\"\sthe text\s(\w+)\./
m = (logLine =~ TEST_LOGLINE_END_REGEX)
if (m.count) {
return [m[1],m[2],m[3]]
} else {
return null
}
}
Run Code Online (Sandbox Code Playgroud)
进行jenkins构建时的输出:
GitHub has been notified of this commit’s build result
java.io.NotSerializableException: java.util.regex.Matcher
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
at java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
at java.util.HashMap.writeObject(HashMap.java:1354)
at sun.reflect.GeneratedMethodAccessor116.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
at …Run Code Online (Sandbox Code Playgroud) java ×3
jenkins ×2
arrays ×1
build.gradle ×1
classloader ×1
converter ×1
encryption ×1
jacoco ×1
jetty ×1
json ×1
jsonschema ×1
kotlin ×1
maven ×1
regex ×1
schema ×1
string ×1