我有一个项目,我想加载一个速度模板来完成它与参数.整个应用程序打包为jar文件.我最初想到的是这样的:
VelocityEngine ve = new VelocityEngine();
URL url = this.getClass().getResource("/templates/");
File file = new File(url.getFile());
ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, file.getAbsolutePath());
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
ve.init();
VelocityContext context = new VelocityContext();
if (properties != null) {
stringfyNulls(properties);
for (Map.Entry<String, Object> property : properties.entrySet()) {
context.put(property.getKey(), property.getValue());
}
}
final String templatePath = templateName + ".vm";
Template template = ve.getTemplate(templatePath, "UTF-8");
String outFileName = File.createTempFile("report", ".html").getAbsolutePath();
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outFileName)));
template.merge(context, writer);
writer.flush();
writer.close();
Run Code Online (Sandbox Code Playgroud)
当我在eclipse中运行时,这很好用.但是,一旦我打包程序并尝试使用命令行运行它,我得到一个错误,因为找不到该文件.
我想问题就在这一行:
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, file.getAbsolutePath()); …Run Code Online (Sandbox Code Playgroud) 我想创建一个这种形式的泛型类:
class MyGenericClass<T extends Number> {}
Run Code Online (Sandbox Code Playgroud)
问题是,我想接受T为Integer或Long,但不是Double.所以只有两个可接受的声明是:
MyGenericClass<Integer> instance;
MyGenericClass<Long> instance;
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我想使用Hibernate Validator来验证一些列.据我所知,问题是java中的\ w标记不接受带有重音符号的字母.
有没有什么方法可以编写正则表达式,以便像Relatório这样的单词可以被验证(我不想写括号之间带有重音的所有字母,因为我希望在很多列中写这个正则表达式)?
我有一个iOS应用程序,我想把它放在持续集成中.我用来做的策略是尝试从命令行运行测试.
我正在尝试使用以下脚本:
TRACETEMPLATE="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
instruments -t $TRACETEMPLATE build/Release-iphonesimulator/MyApp.app -e UIACSCRIPT "UnitTests/SomeTest.js"
Run Code Online (Sandbox Code Playgroud)
SomeTest.js是一个简单的javascript文件,我可以在Xcode中的Instrumentation中运行它可以工作.我用以下方法构建应用程序
xcodebuild -alltargets -sdk iphonesimulator5.1
Run Code Online (Sandbox Code Playgroud)
这会生成MyApp.app.我可以在模拟器中从Xcode运行应用程序就好了,但是,当我尝试通过仪器运行时,我得到一个框,说有一个未知错误,并在命令行中打印:
2012-05-15 15:32:59.928 instruments[17548:1d03] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Failed to start trace.
Run Code Online (Sandbox Code Playgroud)
任何人都可以给我任何关于可能发生的事情的帮助/建议,我该如何解决这个问题?
此外,它总是打开iPad模拟器?我能说它打开我想要的任何模拟器吗?
我知道Stackoverflow中有很多相关的问题,但是我尝试用其中任何一个编写的所有内容,到目前为止,我无法使用它.
我的问题很简单.我有一个Android应用程序,我有一个用户将输入文本的框.但是,我不希望这个文本是多行的(它不应该有"\n"),但如果行的大小大于视口,我希望它包装.所以基本上,我想要的是与Gmail主题字段上的textBox相同的行为.
这是我的全部观点:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question"
android:textAppearance="@style/titleFont"/>
<EditText
android:id="@+id/edit_question_value"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:gravity="top"
android:inputType="textImeMultiLine|textEmailSubject"
android:maxLength="70"
>
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/answer"
android:textAppearance="@style/titleFont"/>
<EditText
android:id="@+id/edit_question_answer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="top"
android:layout_weight="0.7"
android:inputType="textMultiLine"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<Button
android:id="@+id/save_question"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:text="@string/save"/>
<Button
android:id="@+id/cancel_edit_question"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/cancel"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想要具有此行为的文本是id等于@ + id/edit_question_value的文本.到目前为止,我已经能够使它成为真正的多线(因此用户可以输入,如果他想要)或单行,文本将不会换行.也许文本周围的一些元素有一些干扰,这就是为什么我包括整个视图.
有谁知道发生了什么?
好的我想用gradle在模拟器中运行我的测试.
gradle有两个允许我运行测试的目标:
如果我理解正确,我们应该使用deviceCheck来测试模拟器中的东西,但是当我运行它时,不运行任何测试.
connectedCheck也无法正常工作,因为它无法找到设备(仿真器不会像我的手机那样出现在Android Studio中).
我想要的是(理想情况下):
我还希望有一个无法启动或关闭模拟器的目标,但如果一个启动它将使用一个.
可以做任何这些事情吗?我无法在任何地方找到有关如何配置gradle android插件的文档.
我想获取一个.java文件,识别文件中的第一个类,并从此类中获取有关注释,方法和属性的信息.
两种语言中是否都有这样的模块?我也可以构建一个简单的正则表达式,但我不知道如何在正则表达式中识别指示类/方法结束的大括号.
我想创建一个具有以下结构的maven项目:
A
|--pom.xml
|--B
|--pom.xml
|--C
|--pom.xml
Run Code Online (Sandbox Code Playgroud)
其中A,B和C是文件夹,B的pom.xml和C的pom.xml是A的pom.xml的子代.我想在B的pom.xml中有以下部分:
<properties>
<some.property>B</some.property>
</properties>
Run Code Online (Sandbox Code Playgroud)
而在C:
<properties>
<some.property>C</some.property>
</properties>
Run Code Online (Sandbox Code Playgroud)
我希望在某个东西中根据某些属性的值来定义其他几个属性的值.因此,例如,在伪代码中,A会执行以下操作:
if ( some.property == 'B') then
some.other.property = 'some-value-based-on-b'
else if ( some.property == 'C') then
some.other.property = 'some-value-based-on-c'
...
Run Code Online (Sandbox Code Playgroud)
我想运行MVN全新安装指的是的pom.xml(其中包含一个模块部分指向B和C),所以,据我了解,我不能在maven2的项目中使用的配置文件为这个(因为在相同的运行reactor继承了相同的活动配置文件.我可以使用maven3,但是如果它改变了什么就找不到).
有谁知道如何做到这一点?
谢谢,
我正在尝试将日志消息保存到中央数据库.为了做到这一点,我在log4j的xml配置中配置了以下Appender:
<appender name="DB" class="org.apache.log4j.jdbc.JDBCAppender">
<param name="URL" value="jdbc:postgresql://localhost/logging_test" />
<param name="user" value="test_user" />
<param name="password" value="test_password" />
<param name="sql" value="INSERT INTO log_messages ( log_level, message, log_date ) VALUES ( '%p', '%m', '%d{yyyy-MM-dd HH:mm:ss}' )" />
</appender>
Run Code Online (Sandbox Code Playgroud)
这工作正常,除了一些消息包含',然后appender失败.
是否有捷径可寻?