I am trying to operation some java records in a new project. So ns make the project, placed the records in it and also I shot to run the main document so my game starts.

I acquire an error that says selection does not contain a main type.

You are watching: Selection does not contain a main type

I have actually tried several methods to operation it:

Some say to launch eclipse again, tried this a dozen times. In other places someone pointed to open up a brand-new project and make a build path to the old project.

Didn"t work either.

I to be pretty certain it need to work since I ran that a couple of hours earlier at school. Just how do I acquire this working? give thanks to you in advance!


Answers


68
I expect you space trying to run the main course in this way, see screenshot:
*

If not, then try this way. If yes, then you re welcome make sure that your course you room trying come run has actually a main method, that is, the very same method meaning as below:

public static void main(String<> args) // part code hereI hope this will aid you.


Friday, June 4, 2021
*

answered 6 Months back
Axalix
26

Think the Java resource code packages as one big hierarchical namespace. Advertising applications generally live under "com.mycompany.myapp" (the website for this application might be "http://myapp.mycompany.com" although this is obviously not always the case).

How you organize stuff under your myapp package is mainly up come you. The distinction you make for C# in between executable (.exe), DLL"s and also low-level class does no exist in the same type in Java. Every Java source code is compiled right into .class papers (the contents of i m sorry is referred to as "bytecode") which have the right to be executed by a Java Virtual an equipment (JVM) on countless platforms. So there is no inherent difference in high-level/low-level classes, unless you attribute together levels via her packaging. A common means of packaging is:

com.mycompany.myapp: key class; MyApp (with a key method)com.mycompany.myapp.model: domain design classes; Customer, Order, etc. com.mycompany.myapp.ui: user interface (presentation or view) codecom.mycompany.myapp.service: services within your application, i.e. "business logic"com.mycompany.myapp.util: helper classes used in numerous places

this suggests a independent Java app, it could be different if the is a webapp using one of the countless frameworks.

These packages correspond to a catalog hierarchy in your project. As soon as using Eclipse, the root of such a hierarchy is called a "source directory". A task can specify multiple resource directories, commonly a "main" and also a "test" source directory.

Example of records in your project:

src/test/java/com/acme/foo/BarTest.javasrc/main/java/com/acme/foo/Bar.javalib/utilities_1_0.jarAnd within utilities_1_0.jar:

com/acme/foo/BarUtils.classBarUtils.class this is a compiled java class, so in platform independent bytecode kind that have the right to be operation on any type of JVM. Normally jarfiles just contain the compiled great although you can sometimes download a version of the jar that also contains the resource (.java) files. This is helpful if you want to be able to read the original source code of a jar paper you room using.

In the example above Bar, BarTest and BarUtils room all in the exact same package com.acme.foo yet physically reside in various locations on your harddisk.

Classes that reside straight in a source directory space in the "default package", that is typically not a good idea to save classes there because it is no clear come which agency and applications the class belongs and you can acquire name problems if any kind of jar record you add to her classpath contains a class with the exact same name in the default package.

Now if girlfriend deploy this application, the would normally be compiled right into .class files and bundled in a .jar (which is usually a an intricate name because that a .zip document plus some manifest info).Making a .jar is not essential to run the application, but handy when deploying/distributing your application. Making use of the manifest details you have the right to make a .jar file "executable", so the a user can conveniently run it, see .

Usually friend will also be using numerous libraries, i.e. Present .jar records you obtained from the Internet. An extremely common examples are log4j (a logging framework) or JDBC libraries because that accessing a database etc. Likewise you can have your very own sub-modules that are deployed in different jarfiles (like "utilities_1_0.jar" above). How things are break-up over jarfiles is a deployment/distribution matter, lock still every share the global namespace because that Java resource code. For this reason in effect, you could unzip every the jarfiles and also put the materials in one large directory structure if you want to (but you generally don"t).

When to run a Java application which uses/consists of multiple libraries, girlfriend run into what is typically referred to as "Classpath hell". One of the best drawbacks that Java together we know it. (note: aid is supposedly on the way). To run a Java application on the command line (i.e. Not from Eclipse) you have to specify every solitary .jar file location on the classpath. Once you are using among Java"s plenty of frameworks (Maven, Spring, OSGi, Gradle) over there is normally some form of assistance to minimize this pain. If you are structure a internet application friend would generally just have to adhere to its layering/deployment conventions to be able to easily deploy the point in the internet container the your choice (Tomcat, Jetty, Glassfish).

See more:
The Story Of “ We Outnumber Him Resist !” And What Comes Next

I expect this gives some basic insight in exactly how things work-related in Java!

To make an executable jug of the MyApp application you require a JDK on her path. Then use the adhering to command heat in her compile (bin or target) directory:

jar cvfe myapp.jar com.mycompany.myapp.MyApp commycompanymyappYou deserve to then execute the from the command line with:

java -jar myapp.jaror by double-clicking the seasoned file. Note you won"t see the Java console in that instance so this is only useful for applications that have their very own GUI (like a totter app) or that may run in the elevator (like a socket server).