Trouble running Scala file - java

I'm trying to run this Github project. It says that one should run the line scala -cp $CLASSPATH:cgrammar.jar runtime.Main [filename] in order for the application to run.
However, where I run this line with a valid filename, the prompt says "No such file or class on classpath: 'runtime.Main'".
Following the idea of this answer, I tried to run the file with scala -cp $CLASSPATH:cgrammar.jar -e runtime.Main [filename], but now it says that Main is not a member of package runtime.Main.
Can anyone tell me what am I doing wrong here? I don't know if it matters or not, but I'm using Windows.

Related

Javac Compiles Program, but Can't Run with Java

I've never had issues with compiling with javac and running with java before, but here we are.
The program, MainApp.java, depends on a jar file and a few other programs, so I ran the following (which ran without issue):
javac -cp gson.jar *.java
However, when it comes time to run it, I can't seem to get it to work. I've tried:
java -cp gson.jar MainApp.java
but it complains that it can't find the other java files.
I then tried listing the file it said it was missing:
java -cp gson.jar RepositoryData.java MainApp.java
but it gave the same error.
I then tried listing all the dependencies:
java -cp gson.jar Comment.java Issue.java Owner.java Repository.java RepositoryData.java MainApp.java
but it complains that it can't find a main function in the Comment.java file - this leads me to think I'm going about this the wrong way, and I probably shouldn't be directly referencing dependencies in the java call.
I also know that the program does work, as I've compiled it using an editor without issue, but I'm required to do this via the command line for a class.
How should I be properly calling it?

I was able to compile my java code from PowerShell, but cannot run it

I was able to compile and run my java code from CMD, however when I try to run the same commands in PS, I am getting error messages. I have read and been told that CMD commands will work in PS, but the CMD commands are not working in PS
Here is the line that I am using to execute my program:
java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
I am running the command from the directory where my needed JAR files are located. The error message says...
The command stanford-corenlp-3.8.0-models.jar was not found, but does exist
in the current location. Windows PowerShell does not load commands from the
current If you trust this command, instead type: ".\stanford-corenlp-3.8.0-
models.jar".
Made the change and the code looks like this now.
java -classpath .\;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
Still getting the exact same error message. I have also tried going up a directory and no luck. I have looked all over StackOverflow and I have done my research.
Any help would be much appreciated.
Thanks.
Using .\ would work for one file, but since you have a number of files, you should reference the current directory in each one of those files.
java -classpath .\stanford-corenlp-3.8.0.jar;.\stanford-corenlp-3.8.0-javadoc.jar;.\stanford-corenlp-3.8.0-models.jar;.\stanford-corenlp-3.8.0-models.jar .\Test.TestCoreNLP
Java 6 also supports wildcards, as this answer indicates, so you might try simply this.
java -cp ".\*" .\Test.TestCoreNLP
I came here with similar trouble, and what I found is that when running like this:
java -cp .\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar com.ethoca.app.myapp
I would get help info. My discovery is that I need to double-quote my list of classpath, like:
java -cp ".\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar" com.ethoca.app.myapp

"java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver" error when running from terminal

I have a program that I run from Eclipse successfully.
However, when I want to run it from terminal, I encounter the famous error:
"java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver"
on this line:
Class drvClass = Class.forName("oracle.jdbc.driver.OracleDriver");
PS:
I have the following in CLASSPATH:
/oracle/jdbc/lib/ojdbc6.jar
Also note that I compile it successfully (javac Test2.java). Then when I run it (java Test2), I get the following error:
Error: Could not find or load main class Test2
So I run:
java -classpath ~/Desktop/JDBC2/src Test2
It runs, but I get the above "ClassNotFoundException" though.
I found this question tricky: the reason is related to semicolon after jar file address.
At first I changed the directory of MySample.java to another directory (you can don't do that) like C:\
then I removed package address from the source code, at the end I run this command in cmd
java -cp path_to_oracle_driver.jar; MySample
P.S. If you want run it from terminal you have to remove package PackageAddress from the source code and compile it again.
As #yngwietiger mentioned above in the comments, using -classpath parameter when running the .class file, overrides the original CLASSPATH and the predefined ojdbc6.jar file. So we need to mention both when running:
java -classpath ~/Desktop/JDBC2/src:/oracle/jdbc/lib/ojdbc6.jar Test2
Or, as a better solution, we can add the current path to CLASSPATH (note the colon and dot at the end):
export CLASSPATH=$CLASSPATH:.
And, in order to run, we just need to type:
Java Test2

cmd "Error: Could not find or load main class" error

I've read through the other questions and have tried googling the solutions, but I couldn't find the solution I was looking for.
This program compiles and runs on NetBeans, but only complies on CMD. I WANT to get it running with CMD.
I'm not very good with Java - just starting out and this is a uni project.
The program is in a package chess. Move up a folder,
C:\Users\Nihir\Documents\chess> cd ..\
C:\Users\Nihir\Documents> java -cp . chess.Program
You have to use fully qualified names to invoke a class from the commandline. which would be "chess.Program" instead of "Program"
First of all return back to your program directory
cd..
Now simply give the command
java Program

Error: Could not find or load main class HelloWorldApp

I am pretty new to this but I seem to have a problem for a day now, and I can't get around it. Have looked over the other similar post but nothing worked. I just got the basic tutorial, made my Java file.
Used the javac HelloWorldApp.java command and got the class file.
But every time I try to run the java -cp . HelloWorldApp command, I get the Error: Could not find or load main class HelloWorldApp error. Pretty sure I am doing something wrong, just don't know what. I am on a Windows 7 machine with jdk1.8.0_31.
You can simply run your .class file with java filename command, provide you are running it from the src directory
Your current working directory may not be in your classpath, before running java class issue this command to include PWD into your classpath :
set CLASSPATH=%CLASSPATH%;.
java yourAppName

Categories

Resources