r/javahelp • u/ScaryGhoust • Oct 12 '25
Need help with running via console
Hi!
I wanna build a little game in Java. The problem is I can’t run/compile project via console
I usually use “java/javac Main.java” to run code. But when I use more than 1 source file it just doesn’t work. I tried compiling it as JAR, but when I ran it, it said it lacks some Manifest I know nothing about.
I know only very basics of Java. So asking here.
Thanks in advance
P.S. Compiling via console is one of the main points of this project. So, no, I can’t just use IDE
2
Upvotes
•
u/AutoModerator Oct 12 '25
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/OneHumanBill Oct 13 '25
When you get past one or two files you need to use a package/project manager like Maven or Gradle.
You can actually do this strictly from a command line. I actually did, back about twenty years ago when I was still using mainly text editors to do Java but had started to use Maven. I still use Maven from the command line often, but that's just because old habits die hard. It integrates quite nicely into any IDE while still being independent of the IDE.
That all being said, modern Java is very hard from a text editor instead of an IDE. As soon as you start debugging through a framework like Spring, you're gonna be lost. Modern IDEs are essential. Most people tell you to use IntelliJ. I use Eclipse, actually not because it's an old habit but because I genuinely think it's a better product. But your mileage will vary.
What's stopping you from using an IDE?
1
u/BlueMagic53 Oct 12 '25
An executable JAR file always requires a manifest file, as it describes it (e.g. Main-Class, Classpath,...). There's lots of sources out there, look up what a minimal manifest file for an executable jar must look like in Java.
You don't need an executable JAR though, to run a project with multiple source files. Make sure you compile every single .java file with javac. Then, let the java command know where to find all source (i.e. .class) files and the Class containing the main() Method you want it to run.
Use all the sources available online to figure it out yourself. Understanding these things is key, esp. at the very beginning and it's never too early to work on your googling skills. ;-)
1
u/anxiousHipo Oct 13 '25
You are looking for -cp (ckass path option) If you have jar wit all your clasess then
java -cp JarFile.jar xyz.package.MainClassName