无法使用Java启动Activemq。

huangapple 未分类评论43阅读模式
英文:

Unable to start Activemq using Java

问题

我正在尝试在我的Ubuntu机器上启动activemq。我正在尝试使用Java启动服务。以下是我的代码:

Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"/bin/sh", "-c", "cd /home/varkala/Srinivas/Prime360/softwares/apache-activemq-5.5.1/bin;./activemq start"});

我还尝试在bin文件夹中运行run.jar。但没有成功。

rt.exec(new String[]{"/bin/sh", "-c", "cd /home/varkala/Srinivas/Prime360/softwares/apache-activemq-5.5.1/bin;java -jar run.jar start"});

这些是错误日志:

/bin/sh: 1: cd: 无法进入目录 /home/varkala/Srinivas
找不到 startup.sh

但是当我手动打开终端并执行命令时,activemq会启动。我的代码有什么问题吗?

更新:奇怪的是,我尝试使用另一个目录执行cd命令:/home/Varkala/Desktop .. 命令正常工作。但对于上面提到的目录,我收到错误信息。
英文:

I am trying to start activemq on my Ubuntu machine. I am trying to start the service using Java. The below is my code:

Runtime rt=  Runtime.getRuntime();
rt.exec(new String[]{"/bin/sh", "-c", "cd /home/varkala/Srinivas /Prime360/softwares/apache-activemq-5.5.1/bin;./activemq start"});

I also tried to run the run.jar in the bin folder. But it did not work

rt.exec(new String[]{"/bin/sh", "-c", "cd /home/varkala/Srinivas /Prime360/softwares/apache-activemq-5.5.1/bin;java -jar run.jar start"});

These are the error logs:

  /bin/sh: 1: cd: can't cd to /home/varkala/Srinivas
    Can't open startup.sh

But when I open the terminal manually and execute the command , activemq starts. Is there something wrong with my code?

Update: Strangely, I tried to execute the cd command with another directory: /home/Varkala/Desktop .. the command is working fine.But for the above mentioned directory , I am getting error

答案1

得分: 0

这可能不是技术上正确的答案。每当我尝试复制完整路径时,我注意到在我的路径 SrinivasPrime360 之间有一个空格。您可以在我的问题的第一行代码中观察到这一点。对于其他位置(如 桌面)的文件,在复制并粘贴到我的程序中的完整路径时,我没有看到那个空格。我所做的只是将我的文件夹从 Srinivas 重命名为 srinivas,令人惊讶的是,它起作用了。我正在使用 Ubuntu 16.04 LTS。

英文:

This may not be technically correct answer. Whenever I tried to copy the full path , I noticed there is a space between two folders of my path Srinivas and Prime360 .You can observe it in the first line of code in my question.For files in other locations like Desktop , I did not see that space while copying and pasting the full path in my program. All I did was , I renamed my folder from Srinivas to srinivas and surprisingly, it worked . I am using Ubuntu 16.04 LTS

huangapple
  • 本文由 发表于 2020年4月9日 04:16:57
  • 转载请务必保留本文链接:https://java.coder-hub.com/61109308.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定