maven intellij java mapreduce 测试程序
Posted
技术标签:
【中文标题】maven intellij java mapreduce 测试程序【英文标题】:maven intellij java mapreduce test program 【发布时间】:2013-11-27 15:34:17 【问题描述】:我在 IntelliJ 中创建了一个包含三个类文件的 maven 项目:
package mavenKris;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
import java.util.StringTokenizer;
/**
* Created with IntelliJ IDEA.
* User: kshk
* Date: 11/27/13
* Time: 2:27 PM
* To change this template use File | Settings | File Templates.
*/
public class WordMapper extends Mapper<Text,Text,Text,Text>
private Text word = new Text();
public void map(Text key, Text value, Context context) throws IOException, InterruptedException
StringTokenizer itr = new StringTokenizer(value.toString(),",");
while (itr.hasMoreTokens())
word.set(itr.nextToken());
context.write(key, word);
和
package mavenKris;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
/**
* Created with IntelliJ IDEA.
* User: kshk
* Date: 11/27/13
* Time: 2:29 PM
* To change this template use File | Settings | File Templates.
*/
public class AllTranslationsReducer extends Reducer<Text, Text, Text, Text>
private Text result = new Text();
@Override
protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException
String translations = "";
for (Text val : values)
translations += "|" + val.toString();
result.set(translations);
context.write(key, result);
主要...
package mavenKris;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import java.io.IOException;
/**
* Created with IntelliJ IDEA.
* User: kshk
* Date: 11/27/13
* Time: 2:30 PM
* To change this template use File | Settings | File Templates.
*/
public class Dictionary
public static void main(String[] args) throws Exception
Configuration conf = new Configuration();
Job job = new Job(conf, "dictionary");
job.setJarByClass(Dictionary.class);
job.setMapperClass(WordMapper.class);
job.setReducerClass(AllTranslationsReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setInputFormatClass(KeyValueTextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
boolean result = job.waitForCompletion(true);
System.exit(result ? 0 : 1);
这就是 pom.xml 的样子
<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>mavenKris</groupId>
<artifactId>mavenKris</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mavenKris</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>anorak-releases</id>
<url>http://ip-10-40-3-96.cloud.trendinglines.co.uk:8081/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>atlassian-releases</id>
<url>http://repository.opencastproject.org/nexus/content/repositories/atlassian/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>central</id>
<name>Maven Central</name>
<url>http://repo1.maven.org/maven2/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.3-gphd-1.2.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
我正在使用 hadoop 的 greenplum 发行版,现在..当我运行上述项目时,我得到了这个错误....
/usr/java/jdk1.7.0_40/bin/java -Didea.launcher.port=7551 -Didea.launcher.bin.path=/home/kshk/Software/idea-IC-129.1359/bin -Dfile.encoding=UTF-8 -classpath /usr/java/jdk1.7.0_40/jre/lib/jce.jar:/usr/java/jdk1.7.0_40/jre/lib/management-agent.jar:/usr/java/jdk1.7.0_40/jre/lib/resources.jar:/usr/java/jdk1.7.0_40/jre/lib/jfr.jar:/usr/java/jdk1.7.0_40/jre/lib/jsse.jar:/usr/java/jdk1.7.0_40/jre/lib/rt.jar:/usr/java/jdk1.7.0_40/jre/lib/plugin.jar:/usr/java/jdk1.7.0_40/jre/lib/deploy.jar:/usr/java/jdk1.7.0_40/jre/lib/charsets.jar:/usr/java/jdk1.7.0_40/jre/lib/javaws.jar:/usr/java/jdk1.7.0_40/jre/lib/jfxrt.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/zipfs.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/localedata.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunpkcs11.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunec.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/dnsns.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunjce_provider.jar:/home/kshk/IdeaProjects/mavenKris/target/classes:/home/kshk/Software/idea-IC-129.1359/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain mavenKris.Dictionary
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
at mavenKris.Dictionary.main(Dictionary.java:24)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
Process finished with exit code 1
有什么想法吗?
更新:
如果我从命令行指定类路径的路径,它调用 Dictionary 类但给出错误,所以我的 IDE 上必须有一些设置,它没有在运行时指定 hadoop-core 的类路径.....
[kshk@localhost mavenKris]$ /usr/java/jdk1.7.0_40/bin/java -Didea.launcher.port=7537 -Didea.launcher.bin.path=/home/kshk/Software/idea-IC-129.1359/bin -Dfile.encoding=UTF-8 -classpath /usr/java/jdk1.7.0_40/jre/lib/jce.jar:/usr/java/jdk1.7.0_40/jre/lib/management-agent.jar:/usr/java/jdk1.7.0_40/jre/lib/resources.jar:/usr/java/jdk1.7.0_40/jre/lib/jfr.jar:/usr/java/jdk1.7.0_40/jre/lib/jsse.jar:/usr/java/jdk1.7.0_40/jre/lib/rt.jar:/usr/java/jdk1.7.0_40/jre/lib/plugin.jar:/usr/java/jdk1.7.0_40/jre/lib/deploy.jar:/usr/java/jdk1.7.0_40/jre/lib/charsets.jar:/usr/java/jdk1.7.0_40/jre/lib/javaws.jar:/usr/java/jdk1.7.0_40/jre/lib/jfxrt.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/zipfs.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/localedata.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunpkcs11.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunec.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/dnsns.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunjce_provider.jar:/home/kshk/IdeaProjects/mavenKris/target/classes:/home/kshk/Software/idea-IC-129.1359/lib/idea_rt.jar:/home/kshk/.m2/repository/org/apache/hadoop/hadoop-core/1.0.3-gphd-1.2.0.0/hadoop-core-1.0.3-gphd-1.2.0.0.jar com.intellij.rt.execution.application.AppMain mavenKris.Dictionary
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.hadoop.conf.Configuration.<clinit>(Configuration.java:143)
at mavenKris.Dictionary.main(Dictionary.java:25)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
[kshk@localhost mavenKris]$
更新 2:
添加commons-logging-1.0.3.jar的路径后......
[kshk@localhost repository]$ /usr/java/jdk1.7.0_40/bin/java -Didea.launcher.port=7537 -Didea.launcher.bin.path=/home/kshk/Software/idea-IC-129.1359/bin -Dfile.encoding=UTF-8 -classpath /usr/java/jdk1.7.0_40/jre/lib/jce.jar:/usr/java/jdk1.7.0_40/jre/lib/management-agent.jar:/usr/java/jdk1.7.0_40/jre/lib/resources.jar:/usr/java/jdk1.7.0_40/jre/lib/jfr.jar:/usr/java/jdk1.7.0_40/jre/lib/jsse.jar:/usr/java/jdk1.7.0_40/jre/lib/rt.jar:/usr/java/jdk1.7.0_40/jre/lib/plugin.jar:/usr/java/jdk1.7.0_40/jre/lib/deploy.jar:/usr/java/jdk1.7.0_40/jre/lib/charsets.jar:/usr/java/jdk1.7.0_40/jre/lib/javaws.jar:/usr/java/jdk1.7.0_40/jre/lib/jfxrt.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/zipfs.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/localedata.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunpkcs11.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunec.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/dnsns.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunjce_provider.jar:/home/kshk/IdeaProjects/mavenKris/target/classes:/home/kshk/Software/idea-IC-129.1359/lib/idea_rt.jar:/home/kshk/.m2/repository/org/apache/hadoop/hadoop-core/1.0.3-gphd-1.2.0.0/hadoop-core-1.0.3-gphd-1.2.0.0.jar:/home/kshk/.m2/repository/commons-logging/commons-logging/1.0.3/commons-logging-1.0.3.jar com.intellij.rt.execution.application.AppMain mavenKris.Dictionary
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/Configuration
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<init>(DefaultMetricsSystem.java:37)
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<clinit>(DefaultMetricsSystem.java:34)
at org.apache.hadoop.security.UgiInstrumentation.create(UgiInstrumentation.java:51)
at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:216)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:184)
at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:236)
at org.apache.hadoop.security.KerberosName.<clinit>(KerberosName.java:79)
at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:209)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:184)
at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:236)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:466)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:452)
at org.apache.hadoop.mapreduce.JobContext.<init>(JobContext.java:80)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:50)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:54)
at mavenKris.Dictionary.main(Dictionary.java:26)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 21 more
更新 3:
添加:/home/kshk/.m2/repository/commons-configuration/commons-configuration/1.6/commons-configuration-1.6.jar 到路径....
[kshk@localhost repository]$ /usr/java/jdk1.7.0_40/bin/java -Didea.launcher.port=7537 -Didea.launcher.bin.path=/home/kshk/Software/idea-IC-129.1359/bin -Dfile.encoding=UTF-8 -classpath /usr/java/jdk1.7.0_40/jre/lib/jce.jar:/usr/java/jdk1.7.0_40/jre/lib/management-agent.jar:/usr/java/jdk1.7.0_40/jre/lib/resources.jar:/usr/java/jdk1.7.0_40/jre/lib/jfr.jar:/usr/java/jdk1.7.0_40/jre/lib/jsse.jar:/usr/java/jdk1.7.0_40/jre/lib/rt.jar:/usr/java/jdk1.7.0_40/jre/lib/plugin.jar:/usr/java/jdk1.7.0_40/jre/lib/deploy.jar:/usr/java/jdk1.7.0_40/jre/lib/charsets.jar:/usr/java/jdk1.7.0_40/jre/lib/javaws.jar:/usr/java/jdk1.7.0_40/jre/lib/jfxrt.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/zipfs.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/localedata.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunpkcs11.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunec.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/dnsns.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunjce_provider.jar:/home/kshk/IdeaProjects/mavenKris/target/classes:/home/kshk/Software/idea-IC-129.1359/lib/idea_rt.jar:/home/kshk/.m2/repository/org/apache/hadoop/hadoop-core/1.0.3-gphd-1.2.0.0/hadoop-core-1.0.3-gphd-1.2.0.0.jar:/home/kshk/.m2/repository/commons-logging/commons-logging/1.0.3/commons-logging-1.0.3.jar:/home/kshk/.m2/repository/commons-configuration/commons-configuration/1.6/commons-configuration-1.6.jar com.intellij.rt.execution.application.AppMain mavenKris.Dictionary
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
at org.apache.hadoop.metrics2.lib.MetricMutableStat.<init>(MetricMutableStat.java:59)
at org.apache.hadoop.metrics2.impl.MetricsSystemImpl.<init>(MetricsSystemImpl.java:75)
at org.apache.hadoop.metrics2.impl.MetricsSystemImpl.<init>(MetricsSystemImpl.java:120)
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<init>(DefaultMetricsSystem.java:37)
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<clinit>(DefaultMetricsSystem.java:34)
at org.apache.hadoop.security.UgiInstrumentation.create(UgiInstrumentation.java:51)
at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:216)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:184)
at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:236)
at org.apache.hadoop.security.KerberosName.<clinit>(KerberosName.java:79)
at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:209)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:184)
at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:236)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:466)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:452)
at org.apache.hadoop.mapreduce.JobContext.<init>(JobContext.java:80)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:50)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:54)
at mavenKris.Dictionary.main(Dictionary.java:26)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 more
更新 4:
添加:/home/kshk/.m2/repository/commons-lang/commons-lang/2.1/commons-lang-2.1.jar 到类路径
[kshk@localhost tmp]$ /usr/java/jdk1.7.0_40/bin/java -Didea.launcher.port=7537 -Didea.launcher.bin.path=/home/kshk/Software/idea-IC-129.1359/bin -Dfile.encoding=UTF-8 -classpath /usr/java/jdk1.7.0_40/jre/lib/jce.jar:/usr/java/jdk1.7.0_40/jre/lib/management-agent.jar:/usr/java/jdk1.7.0_40/jre/lib/resources.jar:/usr/java/jdk1.7.0_40/jre/lib/jfr.jar:/usr/java/jdk1.7.0_40/jre/lib/jsse.jar:/usr/java/jdk1.7.0_40/jre/lib/rt.jar:/usr/java/jdk1.7.0_40/jre/lib/plugin.jar:/usr/java/jdk1.7.0_40/jre/lib/deploy.jar:/usr/java/jdk1.7.0_40/jre/lib/charsets.jar:/usr/java/jdk1.7.0_40/jre/lib/javaws.jar:/usr/java/jdk1.7.0_40/jre/lib/jfxrt.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/zipfs.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/localedata.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunpkcs11.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunec.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/dnsns.jar:/usr/java/jdk1.7.0_40/jre/lib/ext/sunjce_provider.jar:/home/kshk/IdeaProjects/mavenKris/target/classes:/home/kshk/Software/idea-IC-129.1359/lib/idea_rt.jar:/home/kshk/.m2/repository/org/apache/hadoop/hadoop-core/1.0.3-gphd-1.2.0.0/hadoop-core-1.0.3-gphd-1.2.0.0.jar:/home/kshk/.m2/repository/commons-logging/commons-logging/1.0.3/commons-logging-1.0.3.jar:/home/kshk/.m2/repository/commons-configuration/commons-configuration/1.6/commons-configuration-1.6.jar:/home/kshk/.m2/repository/commons-lang/commons-lang/2.1/commons-lang-2.1.jar com.intellij.rt.execution.application.AppMain mavenKris.Dictionary
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at mavenKris.Dictionary.main(Dictionary.java:37)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
[kshk@localhost tmp]$
编辑:
intellij 中的库 jar
【问题讨论】:
【参考方案1】:由于您是从 IDE 运行它,您应该首先将您的 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>mavenKris</groupId>
<artifactId>mavenKris</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mavenKris</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>anorak-releases</id>
<url>http://ip-10-40-3-96.cloud.trendinglines.co.uk:8081/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>atlassian-releases</id>
<url>http://repository.opencastproject.org/nexus/content/repositories/atlassian/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>central</id>
<name>Maven Central</name>
<url>http://repo1.maven.org/maven2/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.3-gphd-1.2.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
我认为 anorak-releases 是本地 mvn 存储库,并且您在那里有 hadoop-core。检查它是否存在,因为它不适合我,所以我不得不输入:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.2</version>
</dependency>
而不是让它工作。
右键单击 InteliJ 中的 pom 文件并选择“同步 POM”以导入正确的库。然后从 IDE 启动您的程序。
这个命令行之后的样子:
/usr/lib/jvm/java-6-sun-1.6.0.26/bin/java -Didea.launcher.port=7533 -Didea.launcher.bin.path=/opt/instalations/idea-IU-123.169/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-6-sun-1.6.0.26/jre/ lib/jce.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/javaws.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/ lib/plugin.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/charsets.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/ lib/management-agent.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/ jre/lib/jsse.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/deploy.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/ jre/lib/resources.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-6-sun-1.6。 0.26/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-6- sun-1.6.0.26/jre/lib/ext/localedata.jar:/work/eLearning/reactive_scala/hw2/untitled/mavenKris/target/classes:/root/.m2/repository/org/apache/hadoop/hadoop-core /0.20.2/hadoop-core-0.20.2.jar:/root/.m2/repository/commons-cli/commons- cli/1.2/commons-cli-1.2.jar:/root/.m2/repository/xmlenc/xmlenc/0.52/xmlenc-0.52.jar:/root/.m2/repository/commons-httpclient/commons-httpclient/3.0。 1/commons-httpclient-3.0.1.jar:/root/.m2/repository/commons-logging/commons-logging/1.0.3/commons-logging-1.0.3.jar:/root/.m2/repository/ commons-codec/commons-codec/1.3/commons-codec-1.3.jar:/root/.m2/repository/commons-net/commons-net/1.4.1/commons-net-1.4.1.jar:/root /.m2/repository/oro/oro/2.0.8/oro-2.0.8.jar:/root/.m2/repository/org/mortbay/jetty/jetty/6.1.14/jetty-6.1.14.jar: /root/.m2/repository/org/mortbay/jetty/jetty-util/6.1.14/jetty-util-6.1.14.jar:/root/.m2/repository/org/mortbay/jetty/servlet-api- 2.5/6.1.14/servlet-api-2.5-6.1.14.jar:/root/.m2/repository/tomcat/jasper-runtime/5.5.12/jasper-runtime-5.5.12.jar:/root/。 m2/repository/tomcat/jasper-compiler/5.5.12/jasper-compiler-5.5.12.jar:/root/.m2/repository/org/mortbay/jetty/jsp-api-2.1/6.1.14/jsp- api-2.1-6.1.14.jar:/root/.m2/repository/org/mortbay/jetty/jsp-2.1/6.1.14/jsp-2.1-6.1.14 .jar:/root/.m2/repository/org/eclipse/jdt/core/3.1.1/core-3.1.1.jar:/root/.m2/repository/ant/ant/1.6.5/ant-1.6 .5.jar:/root/.m2/repository/commons-el/commons-el/1.0/commons-el-1.0.jar:/root/.m2/repository/net/java/dev/jets3t/jets3t/0.7 .1/jets3t-0.7.1.jar:/root/.m2/repository/net/sf/kosmosfs/kfs/0.3/kfs-0.3.jar:/root/.m2/repository/hsqldb/hsqldb/1.8.0.10 /hsqldb-1.8.0.10.jar:/opt/instalations/idea-IU-123.169/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain mavenKris.Dictionary 字典.txt 输出.txt
【讨论】:
抱歉,我没有了解类路径? AFAIK 我正在从 IntelliJ 执行运行...... 感谢您的回复,我已经复制了新的 pom.xml 但我仍然遇到同样的错误...... 您是否“在 InteliJ 中右键单击 pom 文件并选择“同步 POM”以导入正确的库。然后从 IDE 启动程序。”? 我也使用了 0.20.2 hadoop-core 版本,并且在 sysnchronzation 之后,仍然得到同样的错误..看起来在运行时它找不到类路径.. 它对我有用,但使用 0.20.2 后还有一些其他错误。尝试将 hadoop-core.lib 手动导入您的 IDE。以上是关于maven intellij java mapreduce 测试程序的主要内容,如果未能解决你的问题,请参考以下文章
IntelliJ IDEA 普通java工程怎么转为maven工程
如何在 Intellij 中将“java”文件夹创建到 maven webapp 项目中?
java.sql.SQLException: 找不到适合 jdbc:sqlserver 的驱动程序... (intellij, maven)
Maven配置,使用IntelliJ IDEA和Maven创建Java Web项目