maven install with dependency
증상
메이븐으로 install 한 jar를 실행하면 아래와 같이 ClassNotFoundException이 나타난다.
hadoop jar MyHadoop-0.0.1-SNAPSHOT.jar /home/dh/dev/workspace/testHadoop/output helloworldthisisgood
Exception in thread "main" java.lang.ClassNotFoundException: /home/dh/dev/workspace/testHadoop/output
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.apache.hadoop.util.RunJar.main(RunJar.java:153)
해결
메이븐 install을 할 때 디펜던시들을 같이 jar로 묶는 방법이다.
아래의 코드를 pom.xml에 <build></build> 사이에 집어넣는다. (mainClass는 변경해준다. )
run as -> maven install 을 실행한다.
myproj-0.0.1-SNAPSHOT-jar-with-dependencies.jar 를 실행한다.
<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>org.sample.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>