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
Related
While I have some experience in Python and JavaScript, I am new to Java and am trying it out for the first time. To get started, I went to http://www.java.com, downloaded the dmg there, and then used the package it gave me to install Java. After doing so, I received confirmation that Java had been installed successfully and I closed and trashed the dmg and package. Afterwards, I hopped on my terminal (I am using a Mac running on MacOS Monterey) and tried to use javac on a script I wrote. I received the following error message:
The operation couldn’t be completed. Unable to locate a Java Runtime that supports javac.
Please visit http://www.java.com for information on installing Java.
I went online and did some typical troubleshooting searches. First, I found a site suggesting that I create an environment variable $JAVA_HOME and set it equal to $(/usr/libexec/java_home) in .zshenv (yes, I use zsh not bash). I followed this instruction and when I run echo $JAVA_HOME I get /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home. However, running javac still did not work.
Once more, I went online and this time, I found the suggestion of adding javac to $PATH. So I went into .zshenv and added usr/bin/javac to $PATH (the $PATH export line now looks like this: export PATH="/Users/[redacted]/Library/Python/3.8/bin:/usr/bin/javac:$PATH"). This alteration was confirmed when I exited an reentered terminal and ran echo $PATH. However, once again, running javac yielded the same error.
I feel as if I am facing what must be a pretty common and easily fixable issue, but yet, I haven't yet been able to find a solution that works despite perusal of several other StackOverflow posts and tech articles. Still, I know I'm probably missing something simple, and if this is a duplicate of another question, please link that question in a comment, and I'll take this one down.
Thanks!
I have been trying to get ANTLR to work all day. I have used several websites including antlr.org, numerous StackOverflow queries and the textbook by Terence Parr. I am on a Windows 7 machine (work machine, can't change to Linux) but I have tried this on both CommandPrompt and Cygwin, with the same result.
No matter what I do, when it comes time to use the grun file, I always come up with the same error in the end:
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
Can't load Hello as lexer or parser
I have the most recent versions of the JRE and JDK on my computer, as well as the most recent version of cygwin.
I can run the batch files for grun and antlr4 from anywhere, so I'm strongly guessing my path is set correctly. I can run antlr4.bat with absolutely no issue. It creates every file the text book says I should see:
Hello.g4 HelloBaseListener.java HelloLexer.tokens HelloParser.java Hello.tokens HelloLexer.java HelloListener.java
I can run javac on those files and it generates various CLASS files:
HelloBaseListener.class HelloLexer.class HelloListener.class HelloParser$RContext.class HelloParser.class
But then, when I try to run grun on it, I get this:
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
Can't load Hello as lexer or parser
I've tried several combinations of commands to use the grun file, but the one it says to use in the book is:
grun.bat Hello r -tree
I've also changed the .bat file with grun several times, just to experiment, using different combinations in the books and on the sites, but I always come back to this:
java org.antlr.v4.runtime.misc.TestRig %*
That is what my boss told me to use, and it works for him.
Use this in your grun.bat command
java org.antlr.v4.gui.TestRig %*
I had the same problem, there is actually already a thread with the solution here --> antlr4-Can't load Hello as lexer or parser
The first part of the message "Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically" just means that the TestRig order is saved to another location, it works anyway but I changed my batch data accordingly and did not get the Warning anymore. The second part of the message is the actual problem (see link). In my case I forgot the "." (dot) in my CLASSPATH in Windows.
This is kind of a ridiculous question but I am stucked with it and I need some help.
I am trying to install an open source software in my windows 8 system using command prompt. Everything is set correctly but when I type the final java command, to run the software, I get a series of exceptions.
I am sure that the problem is related with some slashes in the path. I know that the type and number of slashes is important and sometimes java requires this.
So I am not sure if I can get an answer about such a specific question here but I give it a try. This is the path I run in one line:
C:\Kuwaiba7\service>java -Djava.rmi.server.codebase="file:/C:/Kuwaiba7/service/lib/PersistenceAbstractionAPI.jar file:/C:/Kuwaiba7/Service/lib/PersistenceServiceRemoteInterfaces.jar" -jar PersistenceService.jar
I double/tripled checked the paths and tried different variations with the slashes but nothing gives me the expected result.
I get the following exceptions:
java.rmi.serverException
java.rmi.unmarshalException
java.lang.classNotFoundException
This is the format of the path they suggest in their manual but doesn't seem to work either:
Thanks
Dimitris
I found the solution and I post the answer here. Afterall the slashes were correct the way I had them. Although sometimes in Java the number and the type of the slashes counts that wasn't the case here.
What I did before was that I was starting the rmiregistry and then running the PersistenceService. That didn't work.
Then I tried to set the Classpath (from the directory where the PersistenceService.jar is located in my PC). After start the rmiregistry.exe (from the Java directory) and finally run the persistence service as shown above.
That made it work!
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.
Although I'm not new to programming in general, I am new to java, and it seems to work a little bit differently. When trying to compile a .java with javac it gives me this error: cannot find symbol. I looked the cause of this up, and the error occurs when the .class file that you are referencing could not be found. I ensured that all of my references were spelled correctly, I ensured I had the right classpath, I tried compiling a .java file I know is valid, even on an XP computer just in case my Vista installation was the cause, but to no avail. Here are the contents of the .bat I am using to run javac, it could be the cause of my problems.
#echo off
"C:\Program Files (x86)\Java\jdk1.6.0_21\bin\javac" -encoding UTF8 -cp . hl.java
pause
Thank you for the help, this has been troubling me for quite some time now.
Can you show us this?
I tried compiling a .java file I know is valid
Could it be that you are using classes not compiled on . ? Unless your code is as simple as hello world, I'd say chances are high.
This is a long shot, but looking at your script and the error message you described, you're probably not running javac at all. Try this on the command line and see what it says:
C:\Program Files (x86)\Java\jdk1.6.0_21\bin\javac -version
If that doesn't work, then you're not pointing to a valid javac.