我目前正在开发一个现有项目,该项目有一个带有以下内容的pom.xml文件:
<resources>
<resource>
<filtering>false</filtering>
<directory>src</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
我在基本路径中有一个名为properties的目录,其中包含属性文件.我想复制打包属性/在我的src目录下包含的所有属性文件(否则程序会因缺少配置文件而崩溃).
所以我的问题是:
我怎么能用Maven包含不在src目录下的资源文件?
我试试这个,但它似乎不起作用:
<resources>
<resource>
<filtering>false</filtering>
<directory>src</directory>
<includes>
<include>**/*.properties</include>
<include>../properties/**</include>
</includes>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
以下代码适用于模拟器,但无法在Samsung Galaxy S III上运行.
final String[] projection = new String[]
{ ContactsContract.Profile.DISPLAY_NAME };
String name = null;
final Uri dataUri = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
final ContentResolver contentResolver = getContentResolver();
final Cursor c = contentResolver.query(dataUri, projection, null, null, null);
try
{
if (c.moveToFirst())
{
name = c.getString(c.getColumnIndex(ContactsContract.Profile.DISPLAY_NAME));
}
}
finally
{
c.close();
}
System.out.println(name);
Run Code Online (Sandbox Code Playgroud)
这是一个例外:
12-03 20:57:15.751: E/AndroidRuntime(28172): FATAL EXCEPTION: main
12-03 20:57:15.751: E/AndroidRuntime(28172): java.lang.RuntimeException: Unable to start activity ComponentInfo{ht.smca.flashligh/ht.smca.flashligh.MainActivity}: java.lang.NullPointerException
12-03 20:57:15.751: E/AndroidRuntime(28172): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
12-03 20:57:15.751: E/AndroidRuntime(28172): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-03 …Run Code Online (Sandbox Code Playgroud) 我知道,关于这个话题已经有至少一个问题了.但是我想再问一遍,因为这是我在javadoc中Class#getDeclaredMethod(...)发现的:
如果在类中声明了多个具有相同参数类型的方法,并且其中一个方法的返回类型比任何其他方法更具体,则返回该方法; 否则任意选择其中一种方法.
因此,java中反射的开发人员认为这种情况可能是一个问题,或许毕竟可能做这样的声明吗?或者它可能只是被弃用了?
在我的Eclipse Luna SR2(4.4.2)中运行更新后,我安装了m2e 1.6.1.20150625-2338.对于我maven-war-plugin现在使用的项目,我在问题视图中遇到以下错误:

全文:
冲突的生命周期映射(插件执行"org.apache.maven.plugins:maven-war-plugin:2.3:war(执行:war-standalone,phase:package)").要启用完整功能,请删除冲突的映射并运行Maven->更新项目配置.
冲突的生命周期映射(插件执行"org.apache.maven.plugins:maven-war-plugin:2.3:war(执行:war-standalone,phase:package)").要启用完整功能,请删除冲突的映射并运行Maven->更新项目配置.
插件配置不会导致以前版本的m2e出现问题.在pom看起来没问题,没什么不寻常的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<id>war-standalone</id>
<goals>
<goal>war</goal>
</goals>
<phase>package</phase>
<configuration>
...
</configuration>
</execution>
<execution>
<id>war-overlay</id>
<goals>
<goal>war</goal>
</goals>
<phase>package</phase>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
生命周期映射maven-war-plugin未在pom中配置.我检查它是否在父母poms但找不到任何东西.None也在工作空间生命周期映射元数据中.
然后我注意到m2e-wtp插件(映射似乎来自)仍然是旧版本.我将其更新为1.2.0.20150602-1740,但它没有解决问题.
知道如何追踪冲突映射的位置或者如何正确解决问题?
我找到了这个解决方案来构建哈希值:
echo -n wicked | shasum | awk '{print $1}'
Run Code Online (Sandbox Code Playgroud)
但这仅适用于字符串输入。我不知道如何将输入处理为十六进制,例如,如果我想构建 sha1-value 的 sha1-value。
upd:我刚刚发现-bshasum有选项,但它产生错误的输出。它是否期望字节顺序相反?
upd2:例如:我做以下输入:
echo -n 9e38cc8bf3cb7c147302f3e620528002e9dcae82 | shasum -b | awk '{print $1}'
Run Code Online (Sandbox Code Playgroud)
输出是,bed846bb1621d915d08eb1df257c2274953b1ad9但根据哈希计算器,输出应该是9d371d148d9c13050057105296c32a1368821717
upd3:该-b选项似乎根本不起作用。是否应用此参数没有区别,我得到相同的结果。
upd4:整个脚本如下所示。它不起作用,因为空字节在我分配或连接时被删除。
password="wicked"
scrumble="4d~k|OS7T%YqMkR;pA6("
stage1_hash=$(echo -n $password| shasum | awk '{print $1}')
stage2_hash=$(echo $(echo -n $stage1_hash | xxd -r -p | shasum | awk '{print $1}') | xxd -r -p)
token=$(./xor.sh $(echo -n $scrumble$(echo 9d371d148d9c13050057105296c32a1368821717 | xxd -r -p) | …Run Code Online (Sandbox Code Playgroud) 我正在实现一个类Pair,将它用作具有两个值的键HashMap.我使用泛型来保持字段的类型变量.我设法写了代码的最大部分:
public class Pair<L, R>
{
private L left;
private R right;
Pair(L left, R right)
{
this.left = left;
this.right = right;
}
public L getLeft()
{
return left;
}
public R getRight()
{
return right;
}
public void setLeft(L left)
{
this.left = left;
}
public void setRight(R right)
{
this.right = right;
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof Pair< ? , ? >)
{
Pair< ? , ? > …Run Code Online (Sandbox Code Playgroud) 我使用tycho-packaging-plugin来设置jar的输出文件夹.这是我的pom的缩短版本:
<properties>
<tycho-version>0.21.0</tycho-version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<configuration>
<buildDirectory>${project.build.directory}/plugins</buildDirectory>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
如果我执行maven-install,我会收到警告:
[WARNING] Some problems were encountered while building the effective model for com.foo.bar.devtool:com.foo.bar.devtool:eclipse-plugin:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.eclipse.tycho:tycho-packaging-plugin is missing. @ line 44, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
Run Code Online (Sandbox Code Playgroud)
我遵循警告的建议并修改pom: …
根据这篇文章,向Eclipse添加Java 8功能似乎很容易.不知怎的,它不适合我,因为我不能使用新语法,我不能选择环境版本1.8,虽然在eclipse的设置中安装和选择了JDK1.8.安装功能或重启eclipse时没有错误.
平台:Win7 x64
Eclipse版本:Kepler SR2 Build 20140224-0627
有任何想法吗?
我执行以下操作以基于KeyStore中的用户密码存储SecretKey:
// load KeyStore
static byte[] salt = // for learning purposes
{ (byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c,
(byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99 };
String alias = "aeskey";
char[] password = "password".toCharArray();
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(password, salt, 65536, 256);
SecretKey tmp = factory.generateSecret(spec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES/CBC/PKCS5Padding");
Entry aesentry = new KeyStore.SecretKeyEntry(secret);
store.setEntry(alias, aesentry, protParam);
Run Code Online (Sandbox Code Playgroud)
现在我可以从KeyStore获取SecretKey:
KeyStore.SecretKeyEntry e = (SecretKeyEntry) store.getEntry("aeskey", protParam);
secret = e.getSecretKey();
Run Code Online (Sandbox Code Playgroud)
如何从SecretKey获取初始密码?