Tag Archives: package

Error: the main class usertest could not be found or loaded

This class has a specified package

An error occurred when running java test from the command line: the main class usertest could not be found or loaded

    first of all, the user test needs to compile
    the command, such as the folder where the user test.java is located, executes javac user test.java to compile. After compiling, the user test.class file appears in the directory where the user test.java is located, and then it can be run on the command line<

    runs the usertest.class file through the Java command
    first, let’s see what the package name written after the package of the class usertest.java is. My name is com.bean

    when I run Java usertest in the bean directory, I report an error: can't find or load the main class usertest

    later, I see that someone says Java com.bean.usertest can run, and it really can run after a try. But Java usertest can’t run. Later, it is found that this class has a specified package

This class does not specify a package

1. Use javac usertest. Java to compile our. Java file

2. If the java file does not specify a package, just use the Java command to run our class file (Java usertest)

An error was reported when Maven package was running the packaged jar package: there is no main list attribute in xxx.jar, which can be solved by configuring Maven plugin

The command line runs the packaged jar package:

leung@wuyujin simple-webservice-server % java -jar target/sample-1.0-SNAPSHOT.jar 7896
target/sample-1.0-SNAPSHOT.jar There is no master list property in the

Error reason: there is no manifest file in the packaged jar package, which has two lines of configuration, about the full path of the startup class of jar package 0

Add Maven plugin

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>3.0.2</version>
	<configuration>
		 <archive>
		  <manifest>
			   <addClasspath>true</addClasspath>
			   <classpathPrefix>lib/</classpathPrefix>
			   <mainClass>com.coffee.bee.Main</mainClass>
		  </manifest>
		 </archive>
	</configuration>
</plugin>

Plugins
pluginManagement > plugins