我想设计一个shell脚本作为几个脚本的包装器.我想指定myshell.sh使用getopts的参数,并以相同的顺序将其余参数传递给指定的脚本.
如果myshell.sh执行如下:
myshell.sh -h hostname -s test.sh -d waittime param1 param2 param3
myshell.sh param1 param2 -h hostname param3 -d waittime -s test.sh
myshell.sh param1 -h hostname -d waittime -s test.sh param2 param3
Run Code Online (Sandbox Code Playgroud)
所有上述内容都应该可以作为
test.sh param1 param2 param3
Run Code Online (Sandbox Code Playgroud)
是否可以利用选项参数 myshell.sh 并将剩余参数发布到底层脚本?
Java大师,
我很新,annotations并没有搜索过这个,所以请耐心等待...
我想实现Custom Annotation这将intercept一个方法调用.从非常基本的东西开始,它可以只打印方法名称和参数,以便我可以避免使用该logger语句.
像这样的示例调用:
public MyAppObject findMyAppObjectById(Long id) throws MyCustomException {
log.debug("in findMyAppObjectById(" + id + ")");
//....
}
Run Code Online (Sandbox Code Playgroud)
可以转换成:
@LogMethodCall(Logger.DEBUG)
public MyAppObject findMyAppObjectById(Long id) throws MyCustomException {
//....
}
Run Code Online (Sandbox Code Playgroud)
我可以得到一些关于此的提示吗?
这个新的Java 7 try-with-resources构造非常好.或者至少,这是很好的,直到一个例外走过来,毁了我的一天.
我终于把它归结为一个可重复的测试,它只使用JUnit + jMock.
@Test
public void testAddSuppressedIssue() throws Exception {
Mockery mockery = new Mockery();
final Dependency dependency = mockery.mock(Dependency.class);
mockery.checking(new Expectations() {{
allowing(dependency).expectedCall();
allowing(dependency).close();
}});
try (DependencyUser user = new DependencyUser(dependency)) {
user.doStuff();
}
}
// A class we're testing.
private static class DependencyUser implements Closeable {
private final Dependency dependency;
private DependencyUser(Dependency dependency) {
this.dependency = dependency;
}
public void doStuff() {
dependency.unexpectedCall(); // bug
}
@Override
public void close() throws IOException { …Run Code Online (Sandbox Code Playgroud) 我只使用apache-ant而不是 ant-contrib
我有一个ant目标
<target name="stop" depends="init" >
...
</target>
Run Code Online (Sandbox Code Playgroud)
我想在其中调用exec任务.
如果变量的值HOST_NAME是all
<exec executable="${executeSSH.shell}" >
<arg value="-h ${HOST_NAME}" />
<arg value="-i ${INSTANCE}" />
<arg value="-w 10" />
<arg value="-e ${myOperation.shell} " />
<arg value=" -- " />
<arg value="${INSTANCE} ${USERNAME} ${PASSWORD}" />
</exec>
Run Code Online (Sandbox Code Playgroud)
如果变量的值HOST_NAME是anything else
<exec executable="${executeSSH.shell}">
<arg value="-h ${HOST_NAME}" />
<arg value="-i ${INSTANCE}" />
<arg value="-e ${myOperation.shell} " />
<arg value=" -- " />
<arg value="${INSTANCE} ${USERNAME} …Run Code Online (Sandbox Code Playgroud) 我tmp = [null, null, null, Mars, Saturn, Mars]在执行操作后会跟随String Array
-
allSig[d3].split(" ");其中allSig是一个字符串数组.null值是数组中的空值.现在我想删除null.为此,我正在使用
tmp[indexNumber] != null是不工作和给予真实; 取null作为值.即使我使用"null"作为字符串不起作用.
如何删除它.
public static String[] removeElements(String[] allElements) {
String[] _localAllElements = new String[allElements.length];
for (int i = 0; i < allElements.length; i++)
if (allElements[i] != null)
_localAllElements[i] = allElements[i];
return _localAllElements;
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
如何从bash变量中修剪空格?
我搜索并尝试了一些解决方案,但似乎没有什么对我有用......
我有一个shell变量,它导致由于前导和尾随空格引起的问题.我们如何使用shell脚本删除一行中的所有空格?
Java大师,
目前我们有一个经常HashMap<String,SomeApplicationObject>被阅读和偶尔修改的问题,我们遇到的问题是在修改/重新加载期间,Read操作返回null是不可接受的.
要解决这个问题,我有以下选择:
这看起来像是第一选择,但我们所谈论的操作是reload()- 手段clear()紧随其后replaceAll().因此,如果Map是post clear()和pre,replaceAll()则返回null,这是不可取的.即使我synchronize这不解决问题.
B.基于ReentrantReadWriteLock创建另一个实现
在操作Write Lock之前我会在哪里创建获得reload().这似乎更合适,但我觉得必须有一些已经可用的东西,我不需要重新发明轮子.
什么是最好的出路?
编辑任何收藏已经有这样的功能吗?
我想将我的jaxws升级到2.2(jdk1.6与jaxws 2.1捆绑在一起).我的jdk是(我没有安装公共jre):
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)
Run Code Online (Sandbox Code Playgroud)
在jaxws自己的文档中,他们解释了如何做到这一点:
解决此问题的一种方法是将jaxws-api.jar和jaxb-api.jar复制到JRE背书目录中,这是 $JAVA_HOME/lib/endorsed (or $JDK_HOME/jre/lib/endorsed)
但我不确定这对我的安装有什么影响.对于初学者我只定义了%JAVA_HOME%.文件夹$JAVA_HOME/lib/endorsed是不存在的,所以我创建并复制了两个罐子.但是,如果我这样做(wsgen是来自jaxws的工具)
wsgen -version
Run Code Online (Sandbox Code Playgroud)
我还是得到:
JAX-WS RI 2.1.6 in JDK 6
Run Code Online (Sandbox Code Playgroud)
我也试过创建文件夹JAVA_HOME\jre\lib\endorsed(请注意,在文档中他们说JDK_HOME,但因为我只有JAVA_HOME,所以我使用了这个路径).仍然是相同的wsgen输出.
我的问题是:
我发现这篇帖子对我所看到的内容有一些暗示
我正在使用Eclipse进行Android开发,我已经设置了我的代码格式化样式,但仍然有匿名方法,我无法弄清楚如何在Eclipse中进行格式化.这就是Eclipse现在如何格式化匿名方法:
// The BroadcastReceiver that listens for discovered devices and
// changes the title when discovery is finished
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Utils.Log.i("BLUETOOTH: " + action);
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the
// BluetoothDevice
// object from the
// Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// If it's already
// paired, skip it,
// because it's been
// listed already
if (device.getBondState() != BluetoothDevice.BOND_BONDED) { …Run Code Online (Sandbox Code Playgroud) 我想向同事展示SimpleDateFormat 通过简单的JUnit测试不是线程安全的.下面的类没有说明我的观点(在多线程环境中重用SimpleDateFormat),我不明白为什么.你能发现什么阻止我使用SDF抛出运行时异常吗?
public class SimpleDateFormatThreadTest
{
@Test
public void test_SimpleDateFormat_MultiThreaded() throws ParseException{
Date aDate = (new SimpleDateFormat("dd/MM/yyyy").parse("31/12/1999"));
DataFormatter callable = new DataFormatter(aDate);
ExecutorService executor = Executors.newFixedThreadPool(1000);
Collection<DataFormatter> callables = Collections.nCopies(1000, callable);
try{
List<Future<String>> futures = executor.invokeAll(callables);
for (Future f : futures){
try{
assertEquals("31/12/1999", (String) f.get());
}
catch (ExecutionException e){
e.printStackTrace();
}
}
}
catch (InterruptedException e){
e.printStackTrace();
}
}
}
class DataFormatter implements Callable<String>{
static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date;
DataFormatter(Date date){
this.date = date;
} …Run Code Online (Sandbox Code Playgroud) java ×7
bash ×2
shell ×2
annotations ×1
ant ×1
apache ×1
coding-style ×1
eclipse ×1
endorsed ×1
exception ×1
exec ×1
if-statement ×1
interceptor ×1
java-7 ×1
jax-ws ×1
locking ×1
logging ×1
parameters ×1
string ×1
unix ×1