Running Java files inside a package with a jar library - java

Im extremely new to Java so please bear with me.
I would like to run a java project from the terminal.
The directory looks like this :
I went on the terminal inside the "src" folder and tried java InnerFolder.Main but got the following error msg:
Error: Could not find or load main class
How can I run my project?
edit:
compiled files

Related

java.lang.ClassNotFoundException while executing .jar

I have created a .jar of my image processing project which runs on intellij idea.While running .jar using java -jar project.jar it outputs an error Error: Could not find or load main class sample.Main. But when i extract the .jar and go to the inside and open the terminal and then run java sample.Main [sample is the package] , it works perfectly. I think problem may be the class path. How can i solve this.

Error: Could not find or load main class Main when trying to run JAR. Manifest and classpath look fine, still doesn't work?

I've been writing a small system for my job in IntelliJ, building Jars with dependencies as I went along, to check if I could build it in a way that would let it run outside IntelliJ. One day, the Jar started giving me JNI errors when I tried to open it. I looked for ages trying to fix it, and ended up (somewhat) fixing it, by editing my manifest.mf file before building the jar. My manifest file now looks like this:
Manifest-Version: 1.0
Class-Path: C:\Users\mac\IdeaProjects\sqljdbc_6.0\enu\sqljdbc4.jar
Main-Class: Main
(2 blank lines)
The system uses the sqljdbc to connect to an azure database. It compiles and runs perfectly well in intelliJ, but now when I try and run the jar, it gives me the following error: ERROR: Could not find or load main class Main. The main class is not in any package in my program, and it seems like all the options other people have suggested, are already correctly set. I've tried to run it in CMD with java -jar, and with -cp, which results in the same error. Another weird thing is that trying to compile the Main.java file in the CMD gives me a massive stack of nonsensical compilation errors, despite it compiling in intelliJ. Any other ideas...? I'm blank.
Here's the main class:
imports....
public class Main {
public static void main(String[] args) {MWBFrame frame = new MWBFrame("MWB SQL Lookup");
}
}
It creates the main frame of the GUI, which is just an extension of a JFrame.
And here's the CMD output when trying to java -jar it (can't post images yet):
http://imgur.com/nzpx4rn
I think the answer marked for the SO thread How to make a runnable jar file? seems to be helpful for you.
Meanwhile, you can refer to the video http://www.muhlisozdemir.com/blog/how-to-create-executable-jar-files-in-intellij-idea/ from Youtube to know how to create a execute jar files in the IntelliJ IDEA.

can't find main class java program with two jar files?

This is a pretty basic java question but I'm very new to java. I'm trying to follow this guide:
http://www.egtry.com/java/database/jdbc/hello_teradata
my jar files are located in:
tdgssconfig.jar located in /prod/user1/home/tdjar
terajdbc4.jar located in /prod/user1/home/tdjar
I created a file called tdTst.java in /prod/user1/home/tdjar dir with the script in the link above.
I than ran
java -cp ./:terajdbc4.jar tdTst.java
as well as
java -classpath terajdbc4.jar:. tdTst.java
but keep getting this error:
Error: Could not find or load main class tdTst.java
I'm new to java here so what am I doing wrong here? Do I need to point it to both jar files?
Putting the comment as a separate answer as suggested by #rkosegi
Use java -classpath terajdbc4.jar:. tdTst , without the .java

Exporting project in Java(Eclipse)

I wrote a simple game with 2D graphics in Java (Eclipse) and lib Slick2D. When I export project to Runnable Jar File in Eclipse and try to run this file just nothing happens. I can run this game in Eclipse without any problems. When I write java and put my jar in console to get path and hit enter i have sth like that:
C:\Users\Me>java C:\Users\Jolanta\Desktop\pnd.jar Error: Could not
find or load main class C:\Users\Jolanta\Desktop\pnd.jar
In launch configuration while exporting I selected right main class. Any ideas?
it's command for starting jar file with main class:
java -jar C:\Users\Jolanta\Desktop\pnd.jar
You need to provide native libraries along with the jar file. Here are some scripts that will launch your game:
windows (.bat file) :
java -Djava.library.path="native/windows/" -jar pnd.jar
linux :
java -Djava.library.path="native/linux/" -jar pnd.jar
where your directory will look like this:
your .jar and scripts are in the same directory along with 'native' folder.
not sure where I got this folder from, I can send it to you if you want

Trying to run java program for first time outside Eclipse

I'm making a simple card game server in Java using eclipse. I'm now trying to get it to run outside of eclipse.
I did the following
exported it as a jar file, called car4dgameserver.jar
tried to run it by typing java car4dgameserver
I keep getting a error that says
Error:could not find or load main class car4dgameserver
any help on this would be great!
What you need to do is execute it like so:
java -jar card4dgameserver.jar
Hope that helps.
You need to use the -jar option and provide the path to the jar file:
java -jar car4dgameserver.jar

Categories