In the src directory, we will keep. Following are the steps to run java class file which is in different directory: Step 1 Create utility class : Create A. Skip to content. Change Language. Related Articles. Table of Contents. Improve Article. Save Article. Like Article. Attention reader! Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Previous Myth about the file name and class name in Java. As such, the above should work. Using the default package provides some convenience but also some restrictions which I won't elaborate on, but now that you know about the default package you can look it up. I recommend using package names, which is as simple as adding, as you did, something like:. If you do this though, you should put both files in a directory called kugathasan and call javac from the directory containing kugathasan.
It is a package structure issue. You may understand by seeing this screenshot how they look in my IDE and in folder. In Java, you don't normally work directly with the. You work with the. The packages that you create in your IDE should contain your. So instead of putting Pair. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Java referencing a class in the same directory Ask Question. Asked 7 years, 11 months ago. Active 1 year, 2 months ago. Viewed 47k times. How do I get the java compiler to see Pair. Asked 6 years, 2 months ago. Active 6 years, 2 months ago. Viewed 2k times. How do I accomplish running a file from a different folder than the one I am in? Thank you. Improve this question. ParkerHalo, I am not sure what you mean — lefunction.
ParkerHalo no there is no package information — lefunction. Marged the reason is that I am creating the test text file while in the current directory and I am trying to avoid going back and forth between directories. Add a comment. Active Oldest Votes. Improve this answer. When I try the above it says could not find or load main class. I have just edited my answer, I tried it my self and it worked for me, it's like the one you have already posted with your question.
0コメント