以下是我的目录结构
project
|____src/rdfformatter.java
|
pom.xml
所以只有一个档案...... 现在,以下是我的代码:
package org.rdf;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import com.hp.hpl.jena.rdf.model.*;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.rdf.RdfWritable;
public class RdfFormatter extends Configured implements Tool {
// some foo bar
public static void main(String [] args){
//some foo bar
}
}
以下是我的pom文件:
<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>org.rdf</groupId>
<artifactId>rdfreader</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>RDF READER</name>
<!--url>http://maven.apache.org</url-->
<dependencies>
<!--dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency-->
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>2.10.1</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>commons-codec-1.4</artifactId>
<groupId>org.commons</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
当我做的时候
hadoop jar rdfreader-1.0-SNAPSHOT.jar org.rdf.RdfFormatter
我得到了
Exception in thread "main" java.lang.ClassNotFoundException: org.rdf.RdfFormatter
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.hadoop.util.RunJar.main(RunJar.java:149)
我做错了什么?
请注意排除列表..(hadoop有一堆罐子与我正在使用的罐子冲突..否则我收到此错误NoSuchMethodError with slfj4)
答案 0 :(得分:4)
你的源代码应该在src / main / java中,而不是直接在/ src下。
然后应根据包装结构进行布局。
所以你的java文件应该在/src/main/java/org/rdf/RdfFormatter.java
答案 1 :(得分:3)
您的类在src/main/java
的默认目录中没有。所以要么把它放在那里(强烈建议,你应该始终坚持标准,除非有其他明确的理由)或在构建部分指定sourceDirectory
。
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
</build>