我是泽西岛的新手.我需要实现Jersey客户端以POST方法提交数据.curl命令是:
curl -d '{"switch": "00:00:00:00:00:00:00:01", "name":"flow-mod-1", "priority":"32768", "ingress-port":"1","active":"true", "actions":"output=2"}' http://localhost:8080/wm/staticflowentrypusher/json
Run Code Online (Sandbox Code Playgroud)
所以我想弄清楚如何使用Jersey客户端来实现上面的curl命令.
到目前为止我做了:
public class FLClient {
private static Client client;
private static WebResource webResource;
private static String baseuri = "http://localhost:8080/wm/staticflowentrypusher/json";
private static ClientResponse response;
private static String output = null;
public static void main(String[] args) {
try {
client = Client.create();
webResource = client.resource(baseuri);
// implement POST data
} catch (Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?
我是tar命令的新手.我有很多目录中的文件:
1_1_1.txt, 1_1_2.txt,
2_1_1.txt, 2_1_2.txt...
我知道有一个命令:
tar cf file.tar *.txt
Run Code Online (Sandbox Code Playgroud)
将tar所有四个文件都放入file.tar.但我需要tar 1_1_1.txt和1_1_2.txt一个tar文件,2_1_1.txt并2_1_2.txt进入另一个tar文件.我怎么能做到这一点?
我想确保apache2服务已停止.
1. I need to verify if apache2 is installed or not.
Run Code Online (Sandbox Code Playgroud)
当我输入:
sudo /etc/init.d/apache2 stop
Run Code Online (Sandbox Code Playgroud)
我有:
sudo: /etc/init.d/apache2: command not found
Run Code Online (Sandbox Code Playgroud)
这是否意味着没有安装apache2?或者它安装在另一个地方?
2. check apache2 process:
Run Code Online (Sandbox Code Playgroud)
当我输入:
ps a | grep apache2
Run Code Online (Sandbox Code Playgroud)
我有:
10448 pts/4 S+ 0:00 grep --color=auto apache2
Run Code Online (Sandbox Code Playgroud)
这是否意味着apache2正在运行?
3. http://localhost test
Run Code Online (Sandbox Code Playgroud)
我有:
Google Chrome could not connect to localhost
Run Code Online (Sandbox Code Playgroud)
如何验证Apache2是否已停止?
我有一个多线程java项目,我想添加一个方法stop()来停止所有正在运行的线程.问题是这个项目是由其他人开发的,我不熟悉它如何实现多个线程.
我所知道的是,一旦项目开始,就会调用许多线程并且它们会永远运行.有没有办法找到所有正在运行的线程并阻止它们?我搜索了很多,并找到了如何获取正在运行的线程列表:
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
Run Code Online (Sandbox Code Playgroud)
下一步要做什么来阻止所有正在运行的线程?
我想要停止这些线程的原因是我需要将此项目作为一个包部署到OSGi容器.捆绑包启动后,多个线程将永远运行.所以我需要实现一个destroy()方法来阻止所有线程来控制bundle的生命周期.
怎么样
for (Thread t : Thread.getAllStackTraces().keySet())
{ if (t.getState()==Thread.State.RUNNABLE)
t.interrupt();
}
for (Thread t : Thread.getAllStackTraces().keySet())
{ if (t.getState()==Thread.State.RUNNABLE)
t.stop();
}
Run Code Online (Sandbox Code Playgroud) 我使用PHP来显示来自mysql的数据.这是我的css声明:
<style type=”text/css”>
table {
margin: 8px;
}
th {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
background: #666;
color: #FFF;
padding: 2px 6px;
border-collapse: separate;
border: 1px solid #000;
}
td {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
border: 1px solid #DDD;
}
</style>
Run Code Online (Sandbox Code Playgroud)
它们用于显示表格,tableheader,tabledate.我是php css的新手,所以我只是想知道如何在php显示代码中使用上面的css样式:
<?php>
echo "<table>";
echo "<tr><th>ID</th><th>hashtag</th></tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr onmouseover=\"hilite(this)\" onmouseout=\"lowlite(this)\"><td>$row[0]</td> <td>$row[1]</td></tr>\n";
}
echo "</table>";
<?>
Run Code Online (Sandbox Code Playgroud) 我想为OSGi容器创建和部署Web服务.例如,将服务发布到地址:
http://localhost:8080/testservice.
Run Code Online (Sandbox Code Playgroud)
该服务在servlet中生成HTML响应.
我经常搜索并获得:
public class HelloWorldServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hola</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("</body>");
out.println("</html>");
}
}
Run Code Online (Sandbox Code Playgroud)
我需要使用的工具:
maven创建项目
将ESB karaf作为OSGi容器进行保险
问题是我不知道如何使用Maven来创建和实现这样的Web服务,例如:
如何指定 webapp/web.xml
如何指定pom.xml:依赖项,包类型,插件
如何注册服务:实现BundlActivator或配置Spring xml文件
谁能帮我这个?是否有新手的详细教程?
最近我开始学习Hadoop和Mahout.我想知道Hadoop文件系统目录中的目录路径.
在hadoop-1.2.1/conf/core-site.xml中,我指定了:
<property>
<name>hadoop.tmp.dir</name>
<value>/Users/Li/File/Java/hdfstmp</value>
<description>A base for other temporary directories.</description>
</property>
Run Code Online (Sandbox Code Playgroud)
在Hadoop文件系统中,我有以下目录:
lis-macbook-pro:Java Li$ hadoop fs -ls
Found 4 items
drwxr-xr-x - Li supergroup 0 2013-11-06 17:25 /user/Li/output
drwxr-xr-x - Li supergroup 0 2013-11-06 17:24 /user/Li/temp
drwxr-xr-x - Li supergroup 0 2013-11-06 14:50 /user/Li/tweets-seq
-rw-r--r-- 1 Li supergroup 1979173 2013-11-05 15:50 /user/Li/u.data
Run Code Online (Sandbox Code Playgroud)
现在/ user/Li /输出目录在哪里?
我试过了:
lis-macbook-pro:usr Li$ cd /user/Li/output
-bash: cd: /user/Li/output: No such file or directory
Run Code Online (Sandbox Code Playgroud)
所以我认为/ user/Li/output是相对路径而不是绝对路径.
然后我在/ Users/Li/File/Java/hdfstmp中搜索它.有两个文件夹:
DFS
mapred
但我仍然无法在/ Users/Li/File/Java/hdfstmp中找到/ user/Li/output.
我使用Solr 4.6.1的Mac.我试图弄清楚如何使用数据导入来加载数据MySQL.但我最终无法加载JDBC Driver类.这是我做的:
把mysql-connector-java-5.1.29-bin.jar对~/Tools/Solr/example/lib/
1.配置~/Tools/Solr/example/solr/collection1/conf/data-config.xml:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test"
user="root"
password="root"/>
<document>
<entity name="SolrTest"
query="select * from SolrTest">
<field column="ID" name="id"/>
<field column="Name" name="name"/>
<field column="Class" name="class"/>
<field column="Score" name="score"/>
</entity>
</document>
</dataConfig>
Run Code Online (Sandbox Code Playgroud)
2.配置~/Tools/Solr/example/solr/collection1/conf/solrconfig.xml:
在下面添加以下内容 < config> < /config>
<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
Run Code Online (Sandbox Code Playgroud)
也
<lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />
<lib dir="../../../contrib/dataimporthandler/lib" regex=".*\.jar" />
Run Code Online (Sandbox Code Playgroud)
3.添加以下内容~/Tools/Solr/example/solr/collection1/conf/schema.xml:
<field name="id" type="int" indexed="true" stored="true" required="true"/> …Run Code Online (Sandbox Code Playgroud) 我的目标是使用Eclipse创建Restful服务Maven项目.然后将其打包为捆绑包并将其部署到Fuse ESB karaf OSGi容器中.到目前为止,我所知道的是如何使用JAX-RS API注释,@ Path @GET:
package com.restfultest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/example")
public class ExampleService {
@GET
public String sayHello() {
return "Hello Restful service";
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:1.我应该使用什么样的maven原型?maven-archetype-webapp还是快速入门?
2.如何实施Activator?像这样?
public class Activator implements BundleActivator {
private ServiceRegistration<?> registration;
public void start(BundleContext context) throws Exception {
// TODO Auto-generated method stub
ExampleService exampleService = new ExampleService();
registration = context.registerService( ExampleService.class.getName(), exampleService, null );
}
public void stop(BundleContext context) throws Exception {
// TODO Auto-generated method stub
registration.unregister();
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个Maven项目mjbean只有一个依赖项:TestA.这是mjbean的pom.xml:
<groupId>com.mbean</groupId>
<artifactId>mjbean</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Main-Class>com.mbean.Main</Main-Class>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<name>mjbean</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.testa</groupId>
<artifactId>TestA</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
主要课程非常简单:
package com.mbean;
import com.testa.Testcl;
public class Main {
public static void main(String[] args) {
Testcl tcl = new Testcl();
tcl.testmethod();
}
}
Run Code Online (Sandbox Code Playgroud)
我<Main-Class>com.mbean.Main</Main-Class>在maven-bundle-plugin中指定了主类.它与Eclipse运行良好.然后我使用Eclipse在目标文件夹中生成目标包.当我尝试在命令行中运行它时java -jar mjbean-0.0.1-SNAPSHOT.jar,我收到此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/testa/Testcl
at com.mbean.Main.main(Main.java:12) …Run Code Online (Sandbox Code Playgroud) 我想在OSGi容器中两次安装两个相同的bundle或相同的bundle.我使用的OSGi容器是FUSE ESB.这是捆绑信息:
pom.xml中:
<groupId>com.helloworldbundle</groupId>
<artifactId>HelloWorldBundle</artifactId>
<version>1.0.0-SNAPSHOT</version>
Run Code Online (Sandbox Code Playgroud)
蓝图:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="helloworldbundlecopybean"
class="com.helloworldbundle.HelloWorld"
init-method="init" destroy-method="destroy">
</bean>
</blueprint>
Run Code Online (Sandbox Code Playgroud)
第一次安装成功.当我再次尝试安装时,它失败了.然后我制作项目的副本并修改它:
将项目文件夹名称更改为HelloWorldBundleCopy
将工件更改为
<artifactId>HelloWorldBundleCopy</artifactId>
Run Code Online (Sandbox Code Playgroud)
将bean id更改为
<bean id="helloworldbundlecopybeancopy"
Run Code Online (Sandbox Code Playgroud)
但我仍然无法安装修改后的捆绑包:
Error executing command: Error installing bundles:
Unable to install bundle /home/li/Documents/Java/HelloWorldBundleCopy/target/HelloWorldBundleCpoy-1.0.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)
更新到我的问题:
这是我的场景:
我有三个主机:Host1,Host2和Host3
FUSE ESB OSGi容器安装在Host3中.我需要在Host1和Host2上运行一个服务,例如HelloWorld.此服务已在Host3上的FUSE ESB中注册.
这就是为什么我需要使用FUSE ESB两次注册相同的包.
这是我的问题:
是否可以在容器外部运行捆绑包,例如在一台主机上运行HelloWorld捆绑包,但是将其注册到另一台主机上的FUSE ESB?怎么做?我之前做过的实验是通过以下方式在同一台机器上向FUSE ESB注册服务包:
FuseESB:karaf @ root>安装文件:/home/li/Documents/Java/HelloWorldBundle/target/HelloWorldBundle-1.0.0-SNAPSHOT.jar
2.如何修改现有的maven项目以便在不创建新的maven项目的情况下再次安装它?