Please help me get the java command to work - java

I'm learning how to make and run Java programs in Windows with Notepad and the command line. Right now I'm getting a well-known error when I try to run any sort of variant of java Main, Main being the starting class of the program, and I've done some research on it. The error is java.lang.NoClassDefFoundError, but any of the normal solutions for this error don't seem to be helping.
The program is in <root>\com\zork, and the classes are Main, Dungeon, and DungeonMaster, each in the package com.zork. They've all compiled just fine with the javac command, but attempting to run the program with java Main in either <root>\com\zork or just <root> keeps giving me the error above. I've tried many things with -cp, -classpath, and where I'm running java from. The current classpath is
<this directory doesn't matter>;.;"C:\Users\intprof\Desktop\ZORK in Java",
although the last entry has also been C:\Users\intprof\Desktop\ZORK in Java\com\zork, nonexistent, and a couple of other things.
What am I doing wrong? Thanks!

You need to run java com.zork.Main.

Related

How can I run multiple threads in JOMP on Windows (10) from either the command prompt or in Eclipse?

I can't get multiple threads to run using JOMP no matter what I try. I actually can't run a JOMP program from the command line no matter what I try either in fact, although ironically it will compile from there and then run in Eclipse! Even in Eclipse though I only have one thread. I've been through the notes from my university course about installation of JOMP carefully, but they have not helped. I'll be more specific though:
Items in quotes below are from those notes:
"There are a couple of websites that tell you how to make jomp run under Eclipse, see http://www.lst.inf.ethz.ch/teaching/lectures/ss10/24/ assignments/assignment_10/eclipse.txt"
This refers to a now broken link. It also seem to be the only link anyone on forums like Stackoverflow refer to when talking about this issue. Apparently it has instructions on runtime settings for Eclipse to allow multiple threads to run, but since the link is currently broken I can't access those valuable instructions.
"All that is required in order to do that is to ensure that jomp1.0b.jar is on the CLASSPATH"
I ran echo %CLASSPATH% at the command prompt to check if it was on the class path and got the following response:
C:\Program Files\Java\jre1.8.0_162\lib\jomp1.0b.jar
On my PC the jomp jar file is in that folder, so it appears I should be able to execute compiled JOMP programs from the command line, but unfortunately that is not the case. By executing one of these commands it should run:
java −Djomp.threads=2 parallel
java −Djomp.threads=2 -cp . parallel
java −Djomp.threads=2 -cp C:\Users\terry\eclipse-workspace\JOMPHello\src parallel
This is the folder the jomp, java and compiled class files are in. I also checked if "parallel" is the fully qualified class name in the way I have set it up in Eclipse, and it does appears to be. So running one of these commands should allow me to run the jomp program from the command line as near as I can tell, but they all return the following error:
Error: Could not find or load main class parallel
Caused by: java.lang.ClassNotFoundException: parallel
(To which I feel like telling Java, "You're not looking hard it enough! It is right in the folder I am running this command from!")
Clearly I am missing something. Can anyone tell me how to get JOMP programs running on the command line, or alternatively knows where there are accessible instructions for how to set up the work around runtime settings in Eclipse?
My implementation of the program seems to run with only one thread, so hopefully that means it is correct, but I can only be sure once I have run it with at least a few more threads.
Thanks,
Terry.
I figured out how to set up the runtime argument in Eclipse. You just have to add the following line into the VM Arguments box in under the Argument tab in Run Configurations for the file:
−Djomp.threads=n
(where n as before is the number of threads you want).
I'd still like to know why it's not working on the Command Line though. It makes me think my Java is set up weirdly.

eclipse terminates programs without an error

Eclipse has begun terminating any program I try to run before it does anything. The only output is 4.12 printed to the console. It's not just one program with errors, I've tried running old programs that I know worked before but they all exit with 4.12 being printed out.
I tried downloading a new version of eclipse (Mars.1 Release (4.5.1)) but it hasn't really done anything. In the old version it was exiting everything with the code 4.11 so I've run out of ideas to get this to work again.
EDIT
I'm on a mac, using 64-bit.
None of my programs run, I haven't just been leaving the main() empty.
I tried running from the command line and all my programs have changed type from .java to .class
The error I got in the command line was
Class names, 'HelloWorld', are only accepted if annotation processing is explicitly requested
The program running was just hello world.
Try to run your programs via command line, outside of Eclipse, just to make sure it's not an IDE configuration. If still your programs fail, try to re-install your JRE/JDK.
if still the problem occurs - provide us with the exact command line errors.

Running a java program using -cp

so I've checked many posts here and tried everything people suggested and I'm still getting "Could not find or load main class" error, and my professor wasn't very helpful in his answer when I asked for help.
This is what my professor said is supposed to work (he is using OSX).
java -cp classes:lib/json.jar cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
After reading some other posts on this site, I also tried:
java -cp classes:"lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
java -cp "lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
Still nothing works. I'm in the base directory in a bash prompt ~\GroupJsonRPC and the class file that is in ~\GroupJsonRPC\classes\cst420\jsonrpc\client\GroupServerJavaStub.class exists and is ready for running. The same goes for ~\GroupJsonRPC\lib\json.jar. Any insight into how to get this darn thing running would be greatly appreciated!
PS: I'm using Windows.
The proper command is:
java -cp "classes;lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
You need to be sure to include the directory of your class files as well as the jar file(s) with ';' separators, and don't use the -jar option. It invalidates the -cp option.

JDBC classpath issue

I don't like to post a question when so many suggestions pop up when I type the question title in but looking through them all and seeing no solution is somewhat distressing. I've been following a tutorial for java->postgres connections and I am constantly getting slaughtered by
"Could not find or load main class Seb"
error messages.
I've tried using
SET CLASSPATH=%CLASSPATH%:<path to work directory>;<path to jdbc jar>
compiling like so:-
javac -cp .:jdbc.jar Seb.java
and executing like so:-
java -cp .:jdbc.jar Seb
and can't see through the light -_-
The thing is, following the tutorial down to the letter (and watching the demonstration video) doesn't seem to work for me.
I'm simply using notepad and cmd.exe on Windows 8 for development as it's only a learning opportunity, not a big project - but I'm baffled as to why I can't get the thing to run!
JDBC postgres files are in the same directory as .java file.
Code is available if needed as is any other information I can provide.
Thanks in advance for any help,
-Tim!
Use a semi-colon classpath separator for Windows
java -cp .;jdbc.jar Seb
^
Read: PATH and CLASSPATH

Error when starting Datomic shell: java.lang.NoClassDefFoundError: jline/ConsoleRunner

I followed the instructions on the Datomic site: http://docs.datomic.com/getting-started.html, but I'm getting this error when trying to start up the datomic shell prompt. I'm using a windows machine. Any suggestions? I tried the same thing on my linux box and did not get this error.
Edit: moved to a different windows machine and it's working. If I have time to troubleshoot this problem and I find a solution I'll report back
I noticed that you cannot run the shell.cmd from within the bin directory, you need to call it with bin\shell.cmd from the parent directory... hope that helps.
In case you are using cygwin/bash and call bin/shell :
The java runtime on windows does not understand classpath with a ":"
but this is what you get from bin/classpath.
Either correct this or use DOS-CMD shell and call bin/shell.cmd inside.
Regards
Some tips for running datomic on Windows (7 at least):
Do not download datomic into Program Files. On startup, it creates logging directories and temp files into its own directories, so unless you run the command prompt as Administrator, you're gonna have screens full of Unable to write to file... errors.
You need to run datomic as such (assuming you extracted the download to C:)
c:\datomic-free-0.x.xxxx>bin\shell.cmd
Note the backslash. Tripped me up forever coming from *nix world.
After that, return to your regularly scheduled datomic tutorials.

Categories