You should only need jar.with.dependencies.jar -- maven-assembly-plugin's
jar-with-dependencies mode collects all your code and project dependencies
into one jar file. It looks like the problem is that your mainclass is set
to only 'HelloKafkaProducer'. You need to specify the full name
'com.spnotes.kafka.HelloKafkaProducer'. Then running
java -jar jar.with.dependencies.jar
should work. Alternatively, you can put the jar on the class path and then
specify the exact class you want to run
java -cp jar.with.dependencies.jar com.spnotes.kafka.HelloKafkaProducer
On Tue, Jan 20, 2015 at 11:43 AM, Su She <[email protected]> wrote:
> Hello Everyone,
>
> Sorry for the duplicate post, I hadn't subscribed to the list yet, so I
> couldn't reply to suggestions. That has been fixed now.
>
> 1) Using Maven, I wrote a Kafka Producer similar to the one found here:
>
> https://github.com/pppsunil/HelloKafka/blob/master/src/main/java/com/spnotes/kafka/HelloKafkaProducer.java
>
> 2) This is my pom file:
>
> <?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd">
> <modelVersion>4.0.0</modelVersion> <groupId>HelloKafka</groupId>
> <artifactId>HelloKafka</artifactId> <version>1.0-SNAPSHOT</version> <build>
> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-jar-plugin</artifactId> <version>2.2</version> <!--
> nothing here --> </plugin> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-assembly-plugin</artifactId>
> <version>2.2-beta-4</version> <configuration> <descriptorRefs>
> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs>
> <archive> <manifest> <mainClass>HelloKafkaProducer</mainClass> </manifest>
> </archive> </configuration> <executions> <execution> <phase>package</phase>
> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
> </plugins> </build> <dependencies> <dependency>
> <groupId>org.apache.kafka</groupId> <artifactId>kafka_2.10</artifactId>
> <version>0.8.2-beta</version> <scope>compile</scope> <exclusions>
> <exclusion> <artifactId>jmxri</artifactId> <groupId>com.sun.jmx</groupId>
> </exclusion> <exclusion> <artifactId>jms</artifactId>
> <groupId>javax.jms</groupId> </exclusion> <exclusion>
> <artifactId>jmxtools</artifactId> <groupId>com.sun.jdmk</groupId>
> </exclusion> </exclusions> </dependency> <dependency>
> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId>
> <version>1.5.6</version> </dependency> <dependency>
> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId>
> <version>2.10.4</version> </dependency> <dependency>
> <groupId>org.scala-lang</groupId> <artifactId>scala-compiler</artifactId>
> <version>2.10.4</version> </dependency> <dependency>
> <groupId>org.apache.kafka</groupId> <artifactId>kafka_2.10</artifactId>
> <version>0.8.2-beta</version> </dependency> <dependency>
> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId>
> <version>0.3</version> </dependency> <dependency>
> <groupId>com.yammer.metrics</groupId> <artifactId>metrics-core</artifactId>
> <version>2.2.0</version> </dependency> <dependency>
> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId>
> <version>0.8.2-beta</version> </dependency> <dependency>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version>
> </dependency> </dependencies> </project>
>
> 3) I am really lost on how to run kafka producer from the command line. I
> have followed the instructions here as seen in my above pom:
>
> http://stackoverflow.com/questions/1814526/problem-building-executable-jar-with-maven
>
> 4) So I have my HKP.java file, then the pom file I have shown above and
> then I do mvn clean install. It builds the target directory with two jar
> files...what is my next step? I try java -cp jar.with.dependencies.jar -jar
> main.jar, but it says no main manifest attribute. I try java -cp
> jar.with.dependencies HKP, but it says it can't find class HKP
>
> I have a feeling I am not writing the mainClass properly as most online
> examples say com.example.class, but I'm not sure how that translates to
> working on EC2.
>
> Thanks a lot for the help!
>
> -Su
>
--
Thanks,
Ewen