I am setting the VM arguments in eclipse as -DFilePath="C:\file\txt"
But while calling this #FilePath# in java it is giving output as C:filetxt instead of C:\file\txt. This is resulting in file not found exception. Can anyone please help me on this..
The problem must be in how you are "calling this #FilePath#".
I tested with following code:
package test;
import java.io.File;
public class EnvPath {
public static void main(String[] args) {
String path = System.getProperty("FilePath");
System.out.println("Prop: " + path);
File file = new File(path);
System.out.println("File: " + file);
}
}
Started from Eclipse, as you described, or with java -DFilePath="C:\file\txt" test.EnvPath using Windows Command Prompt and using GNU bash - it always produces:
Prop: C:\file\txt
File: C:\file\txt
Related
I have a small program to scan an Integer from console, also I would like to use new line character as delimiter.
import java.util.Scanner;
public class TestScanner {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in).useDelimiter("\n");
System.out.println("Enter the int");
int testInt = scanner.nextInt();
System.out.println(testInt);
}
}
Intellij runs and exist normal way..
Where as Eclipse produce, java.util.InputMismatchException
In Run mode you can observe an exception, with debug mode, code will run with out any issues
Source : jdk1.8.0_161 ( Oracle )
Eclipse :
This is strange. Kindly help me to understand how this can be corrected. Thanking you!
Late but... if you're in Windows you should use "\r\n" instead of just "\n"
I have set up Hadoop v2.7 in my mac and i am able to start the Hadoop daemons.
I would like to write the MR program using eclipse, i need some help to get the hadoop on my eclipse, i would like to know the jar files to be added and basic set up guide
The following is my Driver class code and i couldn't execute it
public class MyJobDriver extends Configured implements Tool {
#Override
public int run(String[] args) throws Exception {
Configuration conf = getConf();
JobConf job = new JobConf(conf, MyJobDriver.class);
Path in = new Path(args[0]);
Path out = new Path(args[1]);
FileInputFormat.setInputPaths(job, in);
FileOutputFormat.setOutputPath(job, out);
job.setJobName("Patent");
job.setMapperClass(InverseMapper.class);
//Input Split consist two values separated by ","
//K1 and V1 type is Text
job.setInputFormat(KeyValueTextInputFormat.class);
job.set("key.value.separator.in.input.line",",");//Everything before the separator is the key and after is the value
job.setOutputFormat(TextOutputFormat.class);//Key and value written as string and separated by tab(default)
//when k1 and k2 are od same type and V1 and V2 are of same type
//we can skip job.setMapOutputKeyClass() and job.setMapOutputValueClass()
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
//jobClient communicates with the JobTrackers to start job across clusters
JobClient.runJob(job);
return 0;
}
public static void main(String[] args) throws Exception {
MyJobDriver driver = new MyJobDriver();
System.out.println("Calling the run method");
int exitCode = ToolRunner.run(driver, args);
System.exit(exitCode);
}
It is too much trouble track and retrieve the necessary jar file (there are many). Instead create a maven project in eclipse and add necessary dependencies as mentioned here https://hadoopi.wordpress.com/2013/05/25/setup-maven-project-for-hadoop-in-5mn/
I have java class in folder D:\myProjects\new_example:
package new_example;
import com.google.gson.Gson;
class MyClass{
public static void main(String[] args) {
MyClass myClass = new MyClass();
Gson gson = new Gson();
System.out.println(gson.toJson(myClass.getMyDate()));
}
public String getMyDate(){
return "Hello";
}
}
How do to run this class in command Line (cmd) from disk D:? (If gson-2.2.4.jar is located: D:\library\gson-2.2.4.jar AND MyClass.java in D:\myProjects\new_example\MyClass.java), use classpath... How do to run it..?
All you need:
en.wikipedia.org/wiki/Classpath_(Java)
I would suggest trying this:
java -cp "jar_name.jar;libs/*" com.test.App
jar_name.jar : your jar name with .jar extension
libs/* : relative path to your dependency jars
com.test.App : Class with main(String[]) method
Try this from the directory D:\myProjects:
java -cp D:\library\gson-2.2.4.jar new_example.MyClass
this is the code from TIJ4#
The java code can compile and run in cmd window , but can not compile and run in eclipse .
//: io/MemoryInput.java
import java.io.*;
public class MemoryInput {
public static void main(String[] args)
throws IOException {
StringReader in = new StringReader(
BufferedInputFile.read("MemoryInput.java"));
int c;
while((c = in.read()) != -1){
System.out.print((char)c);
}
}
the wrong information about the code in eclipse is :
BufferedInputFile cannot be resolved
BufferedInputFile is not part of the package java.io. If you have that class in a library or in a certain folder you have to include it in Eclipse.
BufferedInputFile is not part of any default lib of java. So you have to add that class to your class path.
I posted this on another forum and wanted to see if I can reach more people.
I am working on an application that consists of different Spring web apps.
Say we have:
ComponentA.jar
ComponentB.jar
And WAR files:
Foo.war (contains ComponentA)
Baa.war (contains ComponentA &
ComponentB)
We are using Logback to log to our debug log. So say that the various classes of the application have the the following logger declaration:
private static final Log log = LoggerFactory.getLogger(NAME_OF_WAR_FILE + "." + NAME_OF_CONTAINING_COMPONENT + "." + PACKAGE.CLASS_NAME);
So example:
package a.b.c;
public class SomeClass {
private static final Log log = LoggerFactory.getLogger("Foo.war" + "." + "ComponentA" + "." + SomeClass.class);
}
package x.y.z;
public class SomeOtherClass {
private static final Log log = LoggerFactory.getLogger("Baa.war" + "." + "ComponentA" + "." + SomeOtherClass .class);
}
Assume that the name of the war file and component is set by a property and not hard-coded.
Is it possible to have an Aspect and Advice that can do something like the following (pseudo since I'm not sure it can be done):
#Aspect
public class TheAspect{
#Around("execution of a method")
public Object aroundSomething(ProceedingJoinPoint pjp){
Log log = get the log instance from the class that this advice is running on
if(log.isDebugEnabled())
// log something
Object o = pjp.proceed();
if(log.isDebugEnabled())
// log something else
return o;
}
}
The point here is to write to the log file using the log of the class instance which contains the method which is being intercepted by the Advice.
The application is presented as a single web app composed of Foo.war and Baa.war. Both Foo.war and Baa.war write to the same log file.
Example:
2011-09-22 14:35:35.159 MDT,DEBUG,Foo.war.ComponentA.a.b.c.SomeClass,Hello World Debug message
2011-09-22 14:35:35.159 MDT,DEBUG,Baa.war.ComponentA.a.b.c.SomeClass,Hello World Debug message
2011-09-22 14:35:35.159 MDT,DEBUG,Baa.war.ComponentB.x.y.z.SomeOtherClass,Hello World Debug message
Thanks in advance.
You can use thisJoinPoint inside your aroundSomething method.
To get the class name:
Signature sig = thisJoinPoint.getSignature();
String className = sig.getDeclaringTypeName();
You can also get the class object:
Class<?> type = sig.getDeclaringType();
And maybe you can use the package to identify your war file:
Package pack type.getPackage();