gudii9
asked on
maven project file path
Hi,
I am trying below example
http://technojeeves.com/joomla/index.php/free/132-find-the-current-directory-in-java
when I right click on the CurrentDirectory java file (which is under maven structure 'src/main/java' nd then package 'com\aa\bb\cc\dd\ee\') and click properties it shows
C:\GPDesktop\workspaces\wo rkspace_fi nal\my_ui\ maven_app\ maven_app- web-app\sr c\main\jav a\com\aa\b b\cc\dd\ee \CurrentDi rectory.ja va
But when i run CurrentDirectory java file as 'java application'
I see console output as
C:\GPDesktop\workspaces\wo rkspace_fi nal\my_ui\ maven_app\ maven_app- web-app
I have not understood why current directory shows only "C:\GPDesktop\workspaces\w orkspace_f inal\my_ui \maven_app \maven_app -web-app
" and filters, removes "\src\main\java\com\aa\bb\ cc\dd\ee\"
I wonder why the package names did not came on the console. What is the purpose of packages if they do not show in the current directory.
how is the classpath related to this.
Please advise. Any ideas, resources, sample code highly appreciated. thanks in advance
I am trying below example
http://technojeeves.com/joomla/index.php/free/132-find-the-current-directory-in-java
when I right click on the CurrentDirectory java file (which is under maven structure 'src/main/java' nd then package 'com\aa\bb\cc\dd\ee\') and click properties it shows
C:\GPDesktop\workspaces\wo
package aa\bb\cc\dd\ee
public class CurrentDirectory {
public static void main(String[] args) {
System.out.printf("Current directory is %s\n", System.getProperty("user.dir"));
}
}
But when i run CurrentDirectory java file as 'java application'
I see console output as
C:\GPDesktop\workspaces\wo
I have not understood why current directory shows only "C:\GPDesktop\workspaces\w
" and filters, removes "\src\main\java\com\aa\bb\
I wonder why the package names did not came on the console. What is the purpose of packages if they do not show in the current directory.
how is the classpath related to this.
Please advise. Any ideas, resources, sample code highly appreciated. thanks in advance
ASKER
The "current directory" (also know as the "working directory") has absolutely no bearing on this. This program could be run whilst the current directory is set to "C:\" and it can still work fine and would print out "C:\".
The classpath is actually much more important to all of this. In your case the classpath would have been set to "C:\GPDesktop\workspaces\workspace_f inal\my_ui \maven_app \maven_app -web-app\s rc\main\ja va"
I did not set current directory anywhere. I am simply trying it in my eclipse. How to set Current Directory. Why do we need to set Current Direcory. Please advise
it looks at each path in the classpath (here there is only one) and then appends the package name (with '.' converted to '\'
I am not clear on this. Are there are any detailed links to understand this concept. please advise
I did not set current directory anywhereNo, you didn't. Eclipse sets it for you when it launches your application.
How to set Current Directory.You can change the current directory that is used by right clicking on your project, choose "Run As" -> "Run Configurations...". On the screen that comes up, go to the "Arguments" tab and then at the bottom of that is the option to set the "Working Directory" that will be used to launch your application with.
Why do we need to set Current DirecoryQuite often you don't NEED to set it to anything specific. But note this, it is ALWAYS set to something, even if you don't care what it is set to, every application that you run (Java or otherwise) has a current working directory set.
I am not clear on this.Maybe I confused you with the multiple paths part, so I will make the example even simpler, and we can go from there. Take this example command line to run a Java program...
java -classpath C:\Java\ExampleProject aa.bb.cc.MyMainClass
Just so we are clear on this, all we are doing is starting a JVM, setting the classpath to "C:\Java\ExampleProject" and then asking the JVM to execute a class called "MyMainClass" that is located in the "aa.bb.cc" package. Is this all ok for the moment? (Therefore, "aa.bb.cc.MyMainClass" is what is known as the "fully qualified class name", it is the class name but it has been "fully qualified" by specifying the package name aswell)
Now what the JVM does, in order to actually find the code that it has been asked to run, is fairly simple. It takes the classpath....
C:\Java\ExampleProject
... and appends folders as per the package name ...
C:\Java\ExampleProject\aa\
... and then it looks in that folder for a file that has the name of the class that has been requested to be run, ie. MyMainClass, with the .class file extension. So the full path of the file that the JVM attempts to load is ...
C:\Java\ExampleProject\aa\
That is all that I was trying to explain in the previous post. I don't think it can get much clearer than that. I did a quick Google search and the links that I found were all much more complicated than that!
ASKER
Thank you, Let me check Run Configuration and get back to you.
ASKER
You can change the current directory that is used by right clicking on your project, choose "Run As" -> "Run Configurations...". On the screen that comes up, go to the "Arguments" tab and then at the bottom of that is the option to set the "Working Directory" that will be used to launch your application with.
i see it shows below as default.
C:\\softwares\eclipse-juno
I see "other" option to choose from.
I see "variables" button there. How variable related/useful there. please advise
variables.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The classpath is actually much more important to all of this. In your case the classpath would have been set to "C:\GPDesktop\workspaces\w