Hadoop Java错误:线程“main”中的异常java.lang.ClassNotFoundException:Titanic(Hadoop Java Error : Exception in thread “main” java.lang.ClassNotFoundException: Titanic)
我正在尝试运行一个简单的MapReduce程序来计算男性和女性的平均年龄。 当我试图执行它时,它会给我Class Not Found Exception(泰坦尼克类)。 我发现许多问题提供了类似的答案,并基于我修改了我的程序,但它仍然给我同样的错误。 如果任何人都可以调试它,那将是非常有用的。
import java.io.IOException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.conf.*; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.*; 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; public class Titanic{ public static class Map extends Mapper<LongWritable, Text, Text, IntWritable>{ private Text category = new Text(); public void map(LongWritable key, Text text, Context context) throws IOException, InterruptedException{ String line = text.toString(); String str[] = line.split(","); if(str[4] == "male"){ category.set(str[4]); }else{ category.set(str[4]); } IntWritable value = new IntWritable(Integer.parseInt(str[5])); context.write(category,value); } } public static class Reduce extends Reducer<Text, IntWritable, Text, FloatWritable>{ public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException{ float average = 0; int count =0; for(IntWritable val : values){ average = average+val.get(); count = count + 1; } average =average/count; context.write(key, new FloatWritable(average)); } } public static void main(String[] args) throws Exception{ Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "titanic"); job.setJarByClass(Titanic.class); job.setMapperClass(Map.class); job.setReducerClass(Reduce.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }
}
下面是我执行的命令。
创建一个jar文件:
jar cf example/titanic/titanic.jar example/titanic/Titanic*.class
执行一个jar文件:
bin/hadoop jar example/titanic/titanic.jar Titanic /user/akhil/titanic/input/TitanicData.txt /user/akhil/titanic/output/
I am trying to run a simple MapReduce program which calculates the average age of male and female. When i am trying to execute it, it is giving me Class Not Found Exception (Titanic class). I have found many questions which has provided the similar answer and based on that i have modified my program but still it's giving me same error. It would be really helpfull if anyone can debug it.
import java.io.IOException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.conf.*; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.*; 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; public class Titanic{ public static class Map extends Mapper<LongWritable, Text, Text, IntWritable>{ private Text category = new Text(); public void map(LongWritable key, Text text, Context context) throws IOException, InterruptedException{ String line = text.toString(); String str[] = line.split(","); if(str[4] == "male"){ category.set(str[4]); }else{ category.set(str[4]); } IntWritable value = new IntWritable(Integer.parseInt(str[5])); context.write(category,value); } } public static class Reduce extends Reducer<Text, IntWritable, Text, FloatWritable>{ public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException{ float average = 0; int count =0; for(IntWritable val : values){ average = average+val.get(); count = count + 1; } average =average/count; context.write(key, new FloatWritable(average)); } } public static void main(String[] args) throws Exception{ Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "titanic"); job.setJarByClass(Titanic.class); job.setMapperClass(Map.class); job.setReducerClass(Reduce.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }
}
below are the commands i have executed on it.
creating a jar file:
jar cf example/titanic/titanic.jar example/titanic/Titanic*.class
executing a jar file:
bin/hadoop jar example/titanic/titanic.jar Titanic /user/akhil/titanic/input/TitanicData.txt /user/akhil/titanic/output/
原文:https://stackoverflow.com/questions/39647108
最满意答案
我找到了解决方案,用于查找当前URL以查找添加的标签 - > slug,删除它并获取新URL:
$only_tags = substr($URI, strrpos($URI,'/')+1); $tags = explode('+',$only_tags); $tags_string = implode('+',$tags);
工作代码如下:
for($f = 0, $s = 0; $f <= count($terms_name), $s <= count($terms_slug); $f++, $s++){ if(!empty($result_name[$f]) && !is_category() || !empty($result_slug[$s]) && !is_category() ){ $only_tags = substr($URI, strrpos($URI,'/')+1); $tags = explode('+',$only_tags); foreach ($tags as $t_key=>$t_value) { if ($t_value == $result_slug[$s]) unset ($tags[$t_key]); } $tags_string = implode('+',$tags); echo '<div class="tagCloud-cover" id="cat-hide-'. $s .'"><a class="cat-hide-link" href="'. $URI .'+'. $result_slug[$s] .'" >+</a>'; echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>'; echo '<a href="'. $tags_string .'" >-</a></div>'; if (false !== strpos($Path, $result_slug[$s])) { echo '<style>#cat-hide-'. $s .'{display:none;}</style>'; echo '<div class="tagCloud-cover" id="cat-hide"><span class="cat-hide-link" >+</span>'; echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>'; echo '<a href="'. $tags_string .'" >-</a></div>'; } }
I find solution, what was used to devide current URL for finding added tags->slug, delete it and get new URL:
$only_tags = substr($URI, strrpos($URI,'/')+1); $tags = explode('+',$only_tags); $tags_string = implode('+',$tags);
Working code below:
for($f = 0, $s = 0; $f <= count($terms_name), $s <= count($terms_slug); $f++, $s++){ if(!empty($result_name[$f]) && !is_category() || !empty($result_slug[$s]) && !is_category() ){ $only_tags = substr($URI, strrpos($URI,'/')+1); $tags = explode('+',$only_tags); foreach ($tags as $t_key=>$t_value) { if ($t_value == $result_slug[$s]) unset ($tags[$t_key]); } $tags_string = implode('+',$tags); echo '<div class="tagCloud-cover" id="cat-hide-'. $s .'"><a class="cat-hide-link" href="'. $URI .'+'. $result_slug[$s] .'" >+</a>'; echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>'; echo '<a href="'. $tags_string .'" >-</a></div>'; if (false !== strpos($Path, $result_slug[$s])) { echo '<style>#cat-hide-'. $s .'{display:none;}</style>'; echo '<div class="tagCloud-cover" id="cat-hide"><span class="cat-hide-link" >+</span>'; echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>'; echo '<a href="'. $tags_string .'" >-</a></div>'; } }
相关问答
更多-
如何在Laravel 4路由URL中使用ID和slug?(How to use both ID and slug in Laravel 4 route URL? (resource/id/slug))[2021-12-11]
所以,这就是我最终做的事情: routes.php创建了一个用于show和edit的自定义路由。 剩下的就用一个资源: Route::pattern('id', '[0-9]+'); Route::get('articles/{id}/{slug?}', ['as' => 'articles.show', 'uses' => 'ArticlesController@show']); Route::get('articles/edit/{id}', ['as' => 'articles.edit', ' ... -
问题在于你的网址订购。 url(r'^(?P
\w+)/$', views.profile_page, name='user_profile'), url(r'^(?P [-\w]+)/$', views.project_page, name='user_project'), Django在这些网址中没有太大区别。 Django会从上到下找到第一场比赛。 如果有一个-你的slug它会映射到 url(r'^(?P [-\w]+)/$', views.project_pa ... -
好吧,根据Paulo Almeida的建议,我设法通过覆盖我的EntityDetailView(Detailview)中的get方法来做我想做的事情。 这是最终的代码。 urls.py: url(r'^(?P
\d+)/$', views.EntityRedirectDetailView.as_view(), name='entities-redirect'), url(r'^(?P \d+)/(?P [-\w\d]+)/$', views.EntityDetailView. ... -
我们使用url标记来生成具有给定名称和参数以及关键字参数的uri。 如果您不想使用,那么您需要手动编写每个网址。 这是一个不好的做法。 url(r'^blog/post/(?P
[\w-]+)/$', name='post_detail') 如果你有像上面那样的网址(最好的方法) # post.slug = 'learn-python' {{ post }} # is equivalent to ... -
您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/old_slug(/.*)?$ /$1/new_slug$2 [L,NE,R=302] You can use this code in your DOCUMENT_ROOT/.htaccess file: Rew ...
-
我找到了解决方案,用于查找当前URL以查找添加的标签 - > slug,删除它并获取新URL: $only_tags = substr($URI, strrpos($URI,'/')+1); $tags = explode('+',$only_tags); $tags_string = implode('+',$tags); 工作代码如下: for($f = 0, $s = 0; $f <= count($terms_name), $s <= count($terms_slug ...
-
Wordpress使用get_term来检索slug不按预期工作(Wordpress using get_term to retrieve slug not working as expected)[2023-10-04]
我最近刚刚设置了类似的东西。 这是我用来完成类似的代码: id, 'my-custom-taxonomy-name'); $term = get_term_by( 'id', $terms[0]->term_id, 'my-custom-taxonomy-name'); $parent = get_term($term->parent, 'my-custom-t ... -
WordPress使用htaccess从URL更改或删除自定义帖子slug(WordPress change or remove custom post slug from url using htaccess)[2024-05-05]
请尝试一下这个 RewriteRule ^review/(.*) /products/$1 [L] 这将找到“审查”并将其替换为产品。 i managed this using https://wordpress.org/plugins/custom-permalinks/ this allows me to change any permlinks -
首次RewriteCond后添加此规则: RewriteCond %{REQUEST_FILENAME} !-f Add this rule after first RewriteCond: RewriteCond %{REQUEST_FILENAME} !-f
-
cakephp url修改:删除动作并添加slug inflector(cakephp url modification: remove action and add slug inflector)[2022-04-23]
使用Id和Named参数... 在routes.php上 定义新的路线 - Router::connect('/posts/:id-:title', array('controller' => 'posts', 'action' => 'view') ); 这个新定义的路由将匹配并解析包含id和title命名参数的所有url。 重要说明::在routes.php结束后不要定义新路由。 尝试在文件的中间定义.. 在视图上 echo $this->Html->link('Hi',arr ...