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.

0

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.

0

I have same problem but this solution is not working for me :(

0

@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.

0

Hi,

I have the same issues:

  • I create Maven Project (with ItellijIDEA CE 2016.3.6)
  • Inside I have my package and Main class (mypk.Main)
  • Create artifacts (File > Project Structure > JAR > From module with dependencies > check "Include in project build" > Apply, OK)
  • Build (Build > Build Artifacts)
  • When in console I wrote this command line : "java -jar path/to/file.jar" the output was "Error: Could not find or load main class mypk.Main"

The manifest is into /resources directory:

Manifest-Version: 1.0
Main-Class: mypk.Main

Ps: Inside the .jar, the content of the MANIFEST.MF is the same.

0

Hi,

I avoid the issues, the problem was the dependency

<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-ui_2.10</artifactId>
<version>${dl4j.version}</version>
</dependency>

I don't know why, but if I insert that dependency the jar don't works.

 

0

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).

.

0

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

0

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

0

Gitwithravish - Thank you. This really helped me out. I was having a similar issue after renaming a package.

0

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

0

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

0

请先登录再写评论。