How to run Intellij project from command line - java

I have intellij java project which I run from IDE.
When I run simple java command to run project I get error -
Can any one tell me what is issue here?
Thanks
Nilesh

Please add the .java extension while running the javac command. Something like below:
javac ..... filename.java

Related

Java code runs through IDE but fails from terminal

I have a Java Code where I am able to run it on Intellij using custom configuration. The configuration has following attributes :-
module : java 8 (Oracle OpenJDK 1.8.0_321)
classpath : -cp XYZ.main()
main : com.ABC.XYZ.ManageTraffic
CLI arguements : server XYZ.yml
But when I try to run the jar that was build using gradle from terminal , it gives me Error , could not find or load main class com.ABC.XYZ.ManageTraffic
So far I have tried the following things looking at other solutions at Stackoverflow , still getting the same error
java -jar ques.jar
java -jar ques.jar com.ABC.XYZ.ManageTraffic
java -cp /build/libs/ques.jar com.ABC.XYZ.ManageTraffic
Just to cross check , I unzipped the creataed jar and found that com.ABC.XYZ.ManageTraffic class file is available there , still getting error. What could be the issue?
Run it from the IDE, and while it is running, try to get the command used by the IDE from the process list.
not sure what OS you are using but something like this should work on linux/mac:
ps -ef | grep java
After you have the command you can try to understand why its not working for you, or just use that command
Just want to add how I managed to run it. I created a new shaded jar file of the same application. refreshed its dependencies and now it works. I am yet to find out how creating a shaded jar instead of normal jar helped. Right now the only reason I could figure out is there may be version clashes with some dependencies but I wonder how it could throw could not found main class error.
Anyways , then I ran the file with the following command from terminal:
java -jar ./build/libs/ques-shaded.jar server XYZ.yml

Compiling and running JUnit in command line

I have a project done in Java and we cannot use the IDE to compile it and run it, we are only allowed to use the command line. This project uses JSON. I have managed to successfully compiled and run it as follows:
Compile: javac -cp ./lib/java-json.jar ./src/project/*.java
Run: java -cp ./bin:./lib/java-json.jar project.Main
Now my next step is to run a JUnit test in the command line. To compile I tried:
javac [source files] -cp "path-to-JUnit-jar-files" path-to-JUnit-class
which looks like this:
javac ./src/project/.java -cp "./lib/JUnit/.jar" ./src/testing/AllTests.java
This is the closest I have gotten to successfully compiling the unit test class (I think) because it gave me only a few errors in comparison to other commands I have tried. The errors it gave me are that it needs the classpath to the JSON jar file, but I don't know how to tell the command line to do that.

How to run Slenium+Java+Cucumber without ide

Hello there are tests written on Java + cucumber
The structure is as follows:
https://i.imgur.com/moLVY6L.png
The main question is how to run this tests not from the IDE, say from the console or even wrap it all in jar file
The problems encountered are that you need the main class to create a jar,
It seems as there is a certain java cucumber.api.cli.Main - but how to use it I do not understand. Either way, there's probably a way to run this just from the command line. Please tell us how to do it?
You can download Maven with following terminal script :
$brew install maven
After brew installation, you need to go to the project directory which includes pom.xml file in terminal :
$cd /path/of/your/project
And finally you can run following command to run your tests :
$mvn clean test
You can try the below on command prompt.
java -cp "E:\Workspace\CucumberProj\Jars*;E:\Workspace\CucumberProj\bin" cucumber.api.cli.Main --glue stepDefination E:\Workspace\CucumberProj\Feature\Login_Test.feature

Trouble running Scala file

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.

How to add external jar without Eclipse build path option?

My java file jdbc11.java was compiled successfully with javac jdbc11.java command in cmd, after that when I tried to to run java jdbc11 I got this exception:
java.lang.ClassNotFoundException: com.mysql.jdbc:Driver
refering to this code in the file
Class.forName("com.mysql.jdbc.Driver");
, when I tried it in eclipse ,I added to "Java Build Path" the external jar : mysql-connector-java-5.1.20-bin.jar and it run successfully .
in case I didn't fix it with eclipse what should I done in the first try with java jdbc11 command in order to make work ?
note: the jar in the same dir with the jdbc11.java
Try adding the mysql-connector jar to the classpath when you execute your command-line code:
java -cp mysql-connector-java-5.1.20-bin.jar;. jdbc11
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html
You have to add -classpath in the execute command
java -classpath mysql-connector-java-5.1.20-bin.jar jdbc11
If I'm understanding you allright, what you are missing is a -cp option in your java command line, which is what eclispe would do internally if you were to put it in the build path.

Categories

Resources