running RabbitMq in CMD - eclipse

I'm currently doing the tutorials that can be found on the rabbitMQ webiste and I've run into problems when running the programs in command prompt (Windows7).
Now I have the client libraries working perfectly in Eclipse i.e. I'm able to send messages between a producer and consumer etc. But if I try to run this program in command prompt I get this:
Worker.java:1: error: package com.rabbitmq.client does not exist
import com.rabbitmq.client.Channel;
^
Worker.java:2: error: package com.rabbitmq.client does not exist
import com.rabbitmq.client.Connection;
^
Worker.java:3: error: package com.rabbitmq.client does not exist
import com.rabbitmq.client.ConnectionFactory;
^
etc...... etc..... (this list goes on)....
Now I have added the necessary library (.jar files) locations to the classpath! and compiling in the command prompt using:
javac -cp rabbitmq-client.jar Worker.java
but i'm still getting these issues. If anyone can help I would be most grateful.
Cheers!

I had a similar problem when trying to get RabbitMQ's sample rabbitmq-java-client running (Netbeans on a linux machine). Even though the code in Netbeans said the packages were there, running mnv install or javac would produce tons of errors like:
Send.java:11: error: package com.rabbitmq.client does not exist import
com.rabbitmq.client.ConnectionFactory;
I solved it fixing the structure of the directories. They should look like this:
my-app
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- mycompany
| `-- app
| `-- App.java
`-- test
`-- java
`-- com
`-- mycompany
`-- app
`-- AppTest.java
Please see: http://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project
I think that matches what Maven is looking for.
Also, I rebuilt the pom by hand. The pom in the sample rabbitmq-java-client lacks all this information:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
It just has
<?xml version="1.0"?>
See:
https://github.com/rabbitmq/rabbitmq-java-client/blob/master/pom.xml
Actually, I'm wondering why the poster is doing this in Eclipse.
Now I'm guessing here, but his Worker.java does not need to be edited in an IED. I wonder if we both made the same mistake.
They don't need to be. Just put them in their own directory with these files
commons-cli-1.1.jar
commons-io-1.2.jar
rabbitmq-client.jar
Then
javac -cp rabbitmq-client.jar Worker.java
Open RabbitMQ server (http://localhost:15672/) then
java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Send
next
java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Recv

This is from: https://www.rabbitmq.com/tutorials/tutorial-one-java.html
The Java client library
RabbitMQ speaks AMQP, which is an open, general-purpose protocol for
messaging. There are a number of clients for AMQP in many different
languages. We'll use the Java client provided by RabbitMQ.
Download the client library package, and check its signature as
described. Unzip it into your working directory and grab the JAR files
from the unzipped directory:
$ unzip rabbitmq-java-client-bin-.zip $ cp
rabbitmq-java-client-bin-/*.jar ./ (The RabbitMQ Java client is also
in the central Maven repository, with the groupId com.rabbitmq and the
artifactId amqp-client.)
More details and download the Java client library here: http://www.rabbitmq.com/java-client.html

Related

Eclipse maven project package disorder

Maven project is usually organized as src/main/java/somepackage, but from time to time my eclipse would recognize src/main/java as part of package too. How to fix this?
In the following picture, common and helloworld are both maven projects, where common is organized correctly but helloworld is not.
The src directory is the default directory where Eclipse stores the source code, while in Maven is src/main/java. Better check if the .classpath file has not been corrupted or externally modified. It should contain something like this:
<classpathentry kind="src" output="target/classes" path="src/main/java">
The code line
package main.java.helloworld;
in the helloworld project results in this package hierarchy:
main
`-+ java
`-+ helloworld
Is that really what you mean?
In a maven project, you have this directory structure:
src
`-+ main
| `-+ java
| | `-+ <here your packages and classes>
| '-+ resources
|
'-+ test
| `-+ java
| | `-+ <here your test packages and classes>
| '-+ resources
src/main/java (production code) and src/test/java (tests only) are the root of your package hierarchy. If you create the nested packages com.enterprise within test/java and create a class Test within enterprise, then you have to insert this package declaration in Test.java:
package com.enterprise;
Take a look at your directory and package structure in the helloworld project.

Karaf 3.0.3: MalFormedURLException: Invalid syntax for instruction [Bundle-SymbolicName=

I am creating a simple Bundle in Eclipse Luna Java EE edition and am able to Run the bundle within Eclipse using Equinox framework.
When I export this bundle (Export->Plug-in Development->Deployable Plug-ins and fragments) directly into Karaf-3.0.3's deploy directory, the bundle doesn't start and the karaf log shows (NOTE: Karaf is deployed onto C:\Karaf303 directory). Thanks for any insights:
2015-02-16 09:47:26,747 | ERROR | \Karaf303/deploy | fileinstall | 7 - org.apache.felix.fileinstall - 3.4.2 | Failed to install artifact: C:\Karaf303\deploy\plugins
java.net.MalformedURLException: Invalid syntax for instruction [Bundle-SymbolicName=C:\Karaf303\deploy\plugins]. Take a look at http://www.aqute.biz/Code/Bnd.
at org.ops4j.pax.swissbox.bnd.BndUtils.parseInstructions(BndUtils.java:302)[2:org.ops4j.pax.url.wrap:2.3.0]
at org.ops4j.pax.url.wrap.internal.Parser.<init>(Parser.java:116)[2:org.ops4j.pax.url.wrap:2.3.0]
at org.ops4j.pax.url.wrap.internal.Connection.<init>(Connection.java:67)[2:org.ops4j.pax.url.wrap:2.3.0]
at org.ops4j.pax.url.wrap.internal.Activator$1.createConnection(Activator.java:59)[2:org.ops4j.pax.url.wrap:2.3.0]
at org.ops4j.pax.url.wrap.internal.Activator$1.createConnection(Activator.java:49)[2:org.ops4j.pax.url.wrap:2.3.0]
at org.ops4j.pax.url.commons.handler.HandlerActivator$Handler.openConnection(HandlerActivator.java:222)[2:org.ops4j.pax.url.wrap:2.3.0]
at org.apache.felix.framework.URLHandlersStreamHandlerProxy.openConnection(URLHandlersStreamHandlerProxy.java:271)[org.apache.felix.framework-4.2.1.jar:]
at java.net.URL.openConnection(URL.java:971)[:1.7.0_51]
at java.net.URL.openStream(URL.java:1037)[:1.7.0_51]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:943)[7:org.apache.felix.fileinstall:3.4.2]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:865)[7:org.apache.felix.fileinstall:3.4.2]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:482)[7:org.apache.felix.fileinstall:3.4.2]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[7:org.apache.felix.fileinstall:3.4.2]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[7:org.apache.felix.fileinstall:3.4.2]
Figured out what the problem was - Eclipse is exporting the jar to the specified deploy directory of Karaf, but is placing the jar under a sub-directory, plugins, under deploy. Moving the JAR directly under deploy made it deploy successfully.

run Scala code in package (LinkedIn Norbert)

I am trying to run a Scala object called NorbertClusterClientMain which is in package com.linkedin.norbert.cluster. The source code for it is in folder examples/src/main/scala of rhavyn's open-source branch of LinkedIn Norbert, and I am working on a Linux command line.
Although I've been told that running Scala code in a package is like running Java in a package, I am in examples/src/main/scala but cannot use this command:
$ scala com.linkedin.norbert.cluster.NorbertClusterClientMain
I am getting "No such file or class on classpath", even though the file exists.
I was successfully able to compile Norbert with
$ mvn clean -DskipTests install
How can I run the NorbertClusterClientMain? Please let me know. I appreciate your help.
It is the same. So, in this case, it is looking for this file:
./com/linkedin/norbert/cluster/NorbertClusterClientMain.class
This is how Java works, and since "running" a Scala program is just running java passing the Scala library in the classpath, it has to be the same.
How did you compile it, by the way? Nevermind, saw your comment. At the directory you ran mvn, you should probably be able to run it like this:
scala -cp target com.linkedin.norbert.cluster.NorbertClusterClientMain
Failing that, find the class file, and pass the directory where com/ is to the classpath.
Your mvn script produced JAR and class files within target directory:
./target/com/.../<someClassName1>.class
./target/com/.../<someClassName2>.class
... etc
./target/<someJarName1>.jar
./target/<someJarName2>.jar
... etc
Great! Now do the same thing that you must do for java; include in your classpath:
the target base directory (this "picks up" all class files in directory hierarchy beneath target)
each jar file (this "picks up" all class files in directory hierarchy within each JAR)
scala -cp target:target/<someJarName1>.jar:target/<someJarName2>.jar:... etc ./com.linkedin.norbert.cluster.NorbertClusterClientMain
Here -cp (or equivalently, CLASSPATH environment variable) is the java classpath and so has the same syntax and rules as java.
BTW: "sbt" is a standard, powerful, usable way to build scala projects. It uses Ivy to "pull" dependencies from code repositories (i.e. mvn++). The best way to get started with it is to download sbt example projects, search for "sbt tutorial" blogs and read the sbt docs. :)
I don't anything about the code base, but that class is in the examples subproject.
This shows that it loads normally. (I haven't configured anything, because I don't know anything about the code base.)
apm#mara:~/clones/norbert$ cd examples
/home/apm/clones/norbert/examples
apm#mara:~/clones/norbert/examples$ ls
pom.xml src target
apm#mara:~/clones/norbert/examples$ mvn exec:java -Dexec.mainClass=com.linkedin.norbert.cluster.NorbertClusterClientMain
[INFO] Scanning for projects...
<snip...>
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) # norbert-examples ---
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at com.linkedin.norbert.cluster.NorbertClusterClientMain$.main(NorbertClusterClientMain.scala:22)
at com.linkedin.norbert.cluster.NorbertClusterClientMain.main(NorbertClusterClientMain.scala)
... 6 more
Here's how to add args:
https://stackoverflow.com/a/9846103/1296806
I don't use maven much anymore.
Edit: I don't use Scala 2.7.7 much anymore either.
try $ scala ./com.linkedin.norbert.cluster.NorbertClusterClientMain
or -cp .
you "current directory" might not be in classpath
Norbert uses a Scala 2.7 so directly using Scala from CLI may not work for you. Therefore find all the dependency jar using Maven and use it.
This is how I did it.
First, check out the code:
$ git clone https://github.com/rhavyn/norbert
$ cd norbert/
Build and install the dependencies in local repository first:
$ mvn clean install
Setup a classpath variable which we will use later for examples/ folder:
$ cd examples/
$ export CP=$(mvn dependency:build-classpath | grep -A1 'Dependencies classpath:' | tail -1)
Run server from examples/ folder:
$ java -cp $CP:target/classes com.linkedin.norbert.network.javaapi.NorbertJavaNetworkServerMain arg0 arg1
log4j:ERROR Could not find value for key log4j.appender.R
log4j:ERROR Could not instantiate appender named "R".
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at com.linkedin.norbert.network.javaapi.NorbertJavaNetworkServerMain.main(NorbertJavaNetworkServerMain.java:33)
Run client from examples/ folder:
$ java -cp $CP:target/classes com.linkedin.norbert.cluster.NorbertClusterClientMain localhost 1011
log4j:ERROR Could not find value for key log4j.appender.R
log4j:ERROR Could not instantiate appender named "R".
> h2013-12-20 13:59:44,323 - WARN [pool-1-thread-2-SendThread(0.0.3.243:2181):ClientCnxn$SendThread#1120] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.SocketException: Invalid argument
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:364)
at sun.nio.ch.Net.connect(Net.java:356)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1009)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1036)
2013-12-20 13:59:46,192 - WARN [pool-1-thread-2-SendThread(0.0.3.243:2181):ClientCnxn$SendThread#1120] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.SocketException: Invalid argument
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:364)
at sun.nio.ch.Net.connect(Net.java:356)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1009)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1036)
Thats it. Now all you have to do is setup the required services like Zookeper etc.

Convert jar to C# dll using IKVM - NoClassDefFoundError

i am using IKVM to convert a java jar file to a c# dll.
This jar file has several dependencies, which i referenced all via -r:reference.dll .
Still im getting the following warning and i dont know how to get rid of it:
IKVM.NET Compiler version 7.2.4630.5
Copyright (C) 2002-2012 Jeroen Frijters
http://www.ikvm.net/
warning IKVMC0111: Emitted java.lang.NoClassDefFoundError in "myproject.myclass.setFocus()V"
("org.eclipse.swt.widgets.Control")
The command i am converting the jarfile is:
ikvmc -target:library -debug -out:project.dll -r:org.eclipse.swt.win32.win32.x86_3.5.2.v3557f.dll -r:severalmoreherretofollow project.jar 2> project.log
The class "org.eclipse.swt.widgets.Control" is declared inside the "org.eclipse.swt.win32.win32.x86_3.5.2.v3557f.dll" which had no errors when compiling it with ikvm to a dll.
Thanks in advance
If you compile more as one jar file then it can be recommended to compile it in one step. See the wiki for more details. This prevent you from circulate dependencies.
I think you need to use a full qualified file name with the -r option.

Scala : trying to get log4j working

Scala newb here (it's my 2nd day of using it). I want to get log4j logging working in my Scala script. The script and the results are below, any ideas as to what's going wrong?
[sean#ibmp2 pybackup]$ cat backup.scala
import org.apache.log4j._
val log = LogFactory.getLog()
log.info("started backup")
[sean#ibmp2 pybackup]$ scala -cp log4j-1.2.16.jar:. backup.scala
/home/sean/projects/personal/pybackup/backup.scala:1: error: value apache is not a member of package org
import org.apache.log4j._
^
one error found
I reproduce it under Windows: delimiter of '-classpath' must be ';' there (not ':'). Are you use cygwin or some sort of unix emulator?
But Scala script works anywhere without current dir in classpath. Try to use:
$ scala -cp log4j-1.2.16.jar backup.scala
JFI: LogFactory is a class of slf4j library (not log4j).
UPDATE
Another possible case: broken jar in classpath, maybe during download or something else. Scala interpreter does report only about unavailable member of the package.
$ echo "qwerty" > example.jar
$ scala -cp example.jar backup.scala
backup.scala:1: error: value apache is not a member of package org
...
Need to inspect content of the jar-file:
$ jar -tf log4j-1.2.16.jar
...
org/apache/log4j/Appender.class
...
Did you remember to put log4j.jar in your classpath?
Had Similar issue when started doing Scala Development using Eclipse, doing a clean build solved the problem.
Guess the Scala tools are not matured et.
Instead of using log4j directly, you might try using Configgy. It's the Scala Way™ to work with log4j, as well as configuration files. It also plays nicely with SBT and Maven.
I asked and answered this question myself, have a look:
Put it under src/main/resources/logback.xml. It will be copied to the right location when SBT is doing the artifact assembly.