Cannot find or load main class
已回答
I am trying to run a Java program like:
$ java -jar Neo4jImport.jar
But I get
Error: Could not find or load main class MongoDBImport.App
Where do I look to remove or rename this? I have looked all through the project and could not find MongoDBImport.App. Main should only exists as Neo4jImport.App.
请先登录再写评论。
Assuming you are building the JAR with IntelliJ IDEA via an artifact configuration, go to File > Project Structure > [Project Settings] > Artifacts. Find and select the artifact definition. Toward the bottom middle will be where the manifest file and the main class are defined.
I have same problem but this solution is not working for me :(
@Ramya Can you provide more details on the problem you are having? Are you running a command via the command line or an action in IDEA? What's the error you are getting? Can you paste the content oh the JAR's manifest.mf file? We can then try and determine what the issue might be.
Hi,
I have the same issues:
The manifest is into /resources directory:
Ps: Inside the .jar, the content of the MANIFEST.MF is the same.
Hi,
I avoid the issues, the problem was the dependency
I don't know why, but if I insert that dependency the jar don't works.
I am having the same problem. All applications that I create (I have 5 commercial applications created by IntelliJ using JavaFX) are unavailable to run in terminal and native bundles does not work too. I am using the latest version of IntelliJ (2017.1.3) and used the process described above to create the artifacts.
My manifest file are not copied to generated jar too. It is located at META-INF/MANIFEST.MF. These manifest was defined at Project Settings -> Artifacts.
Another problem that I perceived while I was investigating this problem and can be related with this, is that if I create the sample JavaFX app and move the Controller class to a controller package and sample.fxml to a view package letting the Main class alone at sample package the application will not run anymore and an error will be launched at start up of app if I try to use terminal to launch the app using the generated jar (java -jar javafxapp.jar).
.
Hi to all,
I am having the same problem even when I create a simple java project like a command line app or a java hello world.
/usr/lib/jvm/java-8-oracle/bin/java -javaagent:/mnt/Data/lindev/ideaIU/lib/idea_rt.jar=43819:/mnt/Data/lindev/ideaIU/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar com.company.Main
Error: Could not find or load main class com.company.Main
What can I do to solve the problem?
IntelliJ IDEA 2018.1 (Ultimate Edition)
Build #IU-181.4203.550, built on March 26, 2018
Licensed to Luis Ribeiro
Subscription is active until December 2, 2018
JRE: 1.8.0_152-release-1136-b20 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-37-generic
With best regards,
Luis
Please refer to http://stackoverflow.com/a/42660624/104891.
GOTO Run->Edit Configurations
Ensure that Main Class value is set properly.
I once refactor my package name from 'sample' to 'somethingElse' and then i found error => classNotFound
It was because I changed the package name, but the change was not made implicitly here
Gitwithravish - Thank you. This really helped me out. I was having a similar issue after renaming a package.
in my case helped deleting this line from the file build.gradle
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '8.2.0.jre11'
I don't know why this happens, but after adding the specified library, the compiled jar stops working
Mark Smirnow87 https://stackoverflow.com/a/45169655/104891 is likely the case.
Serge Baranov thanks, but in this case, there must be a way for gradle to automatically remove the signature and manifest from dependencies...
and it's strange why in this case there are no build errors, it just doesn't work without any warnings
Mark it's easy: https://stackoverflow.com/a/51456080/104891