Tag Archives: idea

[Solved] IDEA Start Project Error: Abnormal build process termination:Could not create the Java Virtual Machine.

Idea project startup error

Solution to error reporting during idea project startup

Idea project startup error

Abnormal build process termination: 
"C:\Program Files\Java\jdk1.8.0_161\bin\java.exe" -Xmx700m -Djava.awt.headless=true -Djava.endorsed.dirs=\"\" -Dexternal.project.config=C:\Users\wf870\AppData\Local\JetBrains\IntelliJIdea2021.2\external_build_system\sugar.ad7b8821 -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=3989273803388531595 -Dfile.encoding=GBK -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2021.2 "-Didea.home.path=D:\idea\IntelliJ IDEA 2021.2" -Didea.config.path=C:\Users\wf870\AppData\Roaming\JetBrains\IntelliJIdea2021.2 -Didea.plugins.path=C:\Users\wf870\AppData\Roaming\JetBrains\IntelliJIdea2021.2\plugins -Djps.log.dir=C:/Users/wf870/AppData/Local/JetBrains/IntelliJIdea2021.2/log/build-log "-Djps.fallback.jdk.home=D:/idea/IntelliJ IDEA 2021.2/jbr" -Djps.fallback.jdk.version=11.0.11 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/wf870/AppData/Local/JetBrains/IntelliJIdea2021.2/compile-server/sugar_eaae1db7/_temp_ -Djps.backward.ref.index.builder=true -Djps.track.ap.dependencies=false --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dtmh.instrument.annotations=true -Dtmh.generate.line.numbers=true -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled -Dkotlin.daemon.client.alive.path=\"C:\Users\wf870\AppData\Local\Temp\kotlin-idea-11852903351073037841-is-running\" -classpath "D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/jps-launcher.jar;C:/Program Files/Java/jdk1.8.0_161/lib/tools.jar" org.jetbrains.jps.cmdline.Launcher "D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/maven-resolver-transport-http-1.3.3.jar;D:/idea/IntelliJ IDEA 2021.2/lib/util.jar;D:/idea/IntelliJ IDEA 2021.2/lib/platform-api.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/jps-builders-6.jar;D:/idea/IntelliJ IDEA 2021.2/lib/forms_rt.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/jps-javac-extension-1.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/jps-builders.jar;D:/idea/IntelliJ IDEA 2021.2/lib/3rd-party.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/maven-resolver-connector-basic-1.3.3.jar;D:/idea/IntelliJ IDEA 2021.2/lib/protobuf-java-3.15.8.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/aether-dependency-resolver.jar;D:/idea/IntelliJ IDEA 2021.2/lib/jna.jar;D:/idea/IntelliJ IDEA 2021.2/lib/jna-platform.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/maven-resolver-transport-file-1.3.3.jar;D:/idea/IntelliJ IDEA 2021.2/lib/kotlin-stdlib-jdk8.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/java/lib/javac2.jar;D:/idea/IntelliJ IDEA 2021.2/lib/slf4j.jar;D:/idea/IntelliJ IDEA 2021.2/lib/jps-model.jar;D:/idea/IntelliJ IDEA 2021.2/lib/annotations.jar;D:/idea/IntelliJ IDEA 2021.2/lib/idea_rt.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/JavaEE/lib/jasper-v2-rt.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Kotlin/lib/kotlin-reflect.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Kotlin/lib/kotlin-plugin.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/ant/lib/ant-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/uiDesigner/lib/jps/java-guiForms-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/eclipse/lib/eclipse-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/eclipse/lib/eclipse-common.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/IntelliLang/lib/java-langInjection-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Groovy/lib/groovy-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Groovy/lib/groovy-constants-rt.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/maven/lib/maven-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/gradle-java/lib/gradle-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/devkit/lib/devkit-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/javaFX/lib/javaFX-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/javaFX/lib/javaFX-common.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/JavaEE/lib/javaee-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/webSphereIntegration/lib/jps/javaee-appServers-websphere-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/weblogicIntegration/lib/jps/javaee-appServers-weblogic-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/JPA/lib/jps/javaee-jpa-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Grails/lib/groovy-grails-jps.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Grails/lib/groovy-grails-compilerPatch.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Kotlin/lib/jps/kotlin-jps-plugin.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Kotlin/lib/kotlin-jps-common.jar;D:/idea/IntelliJ IDEA 2021.2/plugins/Kotlin/lib/kotlin-common.jar" org.jetbrains.jps.cmdline.BuildMain 127.0.0.1 52091 2a22c86a-66f8-4710-a186-028d07a1fe2d C:/Users/wf870/AppData/Local/JetBrains/IntelliJIdea2021.2/compile-server
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED

2021.2 idea project startup error:
abnormal build process termination:
error: could not create the Java virtual machine.
error: a fatal exception has occurred. Program will exit.
unrecognized option: — add opens = JDK. Compiler/com. Sun. Tools. Javac. Code = all-unnamed

Idea project startup solution

Many people on the Internet said that the JDK was not installed correctly. At first, they suspected that the JDK was not installed in the default directory, so they reinstalled it and configured the JDK environment. But still report an error. The JDK is re imported in idea again, but it still doesn’t work.

Many methods failed. Finally, it was found that the default project language level was 16 (the idea version used by bloggers was 2021), so it was changed to 8 and the error was reported.

JAVA: How to Use Minio to upload pictures

In the recent project, the Minio drawing bed server is used to upload pictures. Make a record here. The environment of the project is as follows:
Nacos, gradle, springboot, mybatis, MySQL

First, you need to add Minio dependency in gradle. Version 3.0.10 is used in this project

compile 'io.minio:minio:3.0.10'

Then add the configuration class of minioutils in the project to call the service of Minio and provide the interface for calling Minio to upload pictures. All the parameters required in the project are written in the Nacos configuration center. Therefore, take the corresponding parameters from the Nacos configuration file in the annotation form of @ nacosvalue and call the interface for uploading pictures, Returns the URL of a Minio domain name/bucket name/file name stored in the bucket

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.iid.common.helper.IdHelper;
import io.minio.MinioClient;
import io.minio.errors.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.xmlpull.v1.XmlPullParserException;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @ClassName MinioUtils
 * @Description: TODO
 * @Author XuJianSong
 * @Date 2021-01-07
 * @Version V1.0
 **/
@Slf4j
@Component
public class MinioUtils {
    private MinioClient minioClient;
    @NacosValue(value = "${ymukj.minio.endpoint}")
    private String endPoint;
    @NacosValue(value = "${ymukj.minio.accessKey}")
    private String accessKey;
    @NacosValue(value = "${ymukj.minio.secretKey}")
    private String secretKey;
    @NacosValue(value = "${ymukj.minio.preUrl}")
    private String preUrl;

    @PostConstruct
    public void initMinioClient() {
        try {
            minioClient = new MinioClient(endPoint, accessKey, secretKey);
        } catch (InvalidEndpointException e) {
            log.error(e.getMessage(), e);
        } catch (InvalidPortException e) {
            log.error(e.getMessage(), e);
        }
    }

    public String uploadFile(String bucketName, String objName, InputStream inputStream, Long lenght, String contentType) {
        // Use putObject to upload a file to the storage bucket.
        try {
            minioClient.putObject(bucketName, objName, inputStream, lenght, contentType);
            boolean isExist = minioClient.bucketExists(bucketName);
            if (!isExist) {
                minioClient.makeBucket(bucketName);
            }
            return preUrl+"/"+objName;
        } catch (Exception e) {
            e.printStackTrace();
            log.info(">>>>>>>>>>>>>>>>>>>>>>>>>Error:" + e);
            return null;
        }
    }
}

In Minio, there is the concept of “bucket”. The so-called bucket is the folder on the Minio drawing bed. If the bucket name passed to the parameter already exists on the drawing bed, the uploaded picture will be stored in the current bucket
if the bucket name transferred to the parameter does not exist on the drawing bed, the bucket will be created in the source code method first and then saved

As shown in the figure: the bucket in the Minio drawing bed is on the left, and the files in the bucket are on the right. Minio supports uploading all files. Video and document files are OK, but these functions are not involved in the project, which will be studied later

The next step is to write the interface for uploading pictures in the project. Because it does not involve the operation of the database, I directly wrote all the interfaces in the controller layer and did not call the method of the service layer
the controller layer interface receives the file parameters from the front end, and then processes the files according to the requirements of the parameters received by the method for uploading pictures in the minioutils configuration class, First, we can see that the upload image interface in the miniutils configuration file requires four parameters: bucket, objname, InputStream, lenght and contenttype. The four parameters are: bucket name, file name uploaded and saved to bucket, file input stream and file type. If the upload is successful, a URL will be returned. Put the URL in the browser to directly open the picture. If you need to use the picture in the project, you can directly store the URL in the database and get it from the database later

public GlobalResponse uploadPic(MultipartFile file) {
    String bucket = "pic";
    String filename = file.getOriginalFilename();
    String[] exts = filename.split("\\.");
    String ext = exts[exts.length - 1];
    String caselsh = filename.substring(0,filename.lastIndexOf("."));
    String objName = SystemHelper.now() + caselsh + "." + ext;
    log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>objName:" + objName);
    String contentType = file.getContentType();
    InputStream inputStream = null;
    Long lenght = null;
    try {
        inputStream = file.getInputStream();
        lenght = Long.valueOf(inputStream.available());
    } catch (IOException e) {
        e.printStackTrace();
    }
    String picUrl = minioUtils.uploadFile(bucket, objName, inputStream, lenght, contentType);
    log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>picUrl:" + picUrl);
    return GlobalResponse.success(picUrl);
}

Note that the file name uploaded to the bucket should not be repeated! Don’t repeat! Don’t repeat
because duplicate file names can cause a problem: for example, if you upload a picture a.png first and save it in the bucket with the name 111.png, then the Minio domain name/bucket name/111.png can directly open the picture a.png, but if you upload a picture B.png and save it to the same name 111.png, then the Minio domain name/bucket name/111.png opens the picture B.png, If the picture a.png has been stored in the database and has been used, the consequences can be imagined
therefore, the solution used in the interface is to use the form of timestamp + original file name + suffix. Because the timestamp is 13 bits and milliseconds, even if a file with the same name is uploaded, there will be no problem that the file name saved in the bucket will be repeated

That’s all for this sharing. If you have any mistakes, please correct them!

Used by: Java. Lang. classnotfoundexception: org. PostgreSQL. Driver

Always report an error saying that failed by: Java. Lang. classnotfoundexception: org. PostgreSQL. Driver

After a series of searching to find out the reasons, such as the quotation in the box is wrong, I can’t quote what I need;

Only the writing method as shown in the figure below can be quoted successfully,

In memory of the time I’ve been tossing about, it’s also a small lesson of using gradlew for the first time

MacOS: How to Fix Intellij-IDEA main menu disappears Bug

I found a lot of blogs and tried them, but they didn’t work. I wasted a lot of time, such as preference  & gt;   keymap   & gt; Main menu has many methods. Finally, we found a solution on stackoverflow

idea-community version 2021.1

macOS 10.14

Follow these steps:

Step1: shortcut key shift + shift (or CMD + Shift + a)

Step 2: enter vmoptions to see the idea.vmoptions file

Step3: edit file, add at the end:

-Dapple.laf.useScreenMenuBar=false

Step 4: restart idea

Not registered via @EnableConfigurationProperties or marked as Spring component

In springboot, there are the following problems when binding the properties in the class with the configuration in the configuration file:

When using @ configurationproperties, the following prompt appears at the top of idea:

Click the prompt to jump to the official document, and then add the following configuration in POM. XML

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

The effect after adding is that when you write the configuration file (YML, properties configuration file), you will be prompted

After the above is finished, @ configurationproperties will report an error below. You can see it according to the prompt

Not registered via @ enableconfigurationproperties or marked as spring component    @ Enable configuration properties (person. Class),

After adding, the error is really gone, but in the unit test of springboot, you will see the following error: could not autowire. No beans of ‘person’ type found

  Go back to the user-defined bean person, add the annotation @ component and declare to add the component to the container so that it can be used?

“Only if this component is a component in the container can the @ configurationproperties function provided by the container be used.”

Fatal error matching: invalid target distribution: 11

Idea executes Maven command and prompts fatal error matching: invalid target distribution: 11

Environmental Science:

        Project JDK version: 11

        Environment variable JDK version: 1.8

        Maven version: 3.3.9

 
Querying the data, we found that when executing the Maven command, we will find the JDK version of the environment variable, so the JDK version does not match the JDK version of the project

Treatment method

1. Before executing the Maven command, execute the command:

set JAVA_HOME=D:\Java\jdk\adopt-openjdk-11.0.11

After execution, execute the Maven command

2. Modify environment variable Java_ Home, configured as jdk11 directory  

Because most of my projects use JDK1.8, only a few projects use jdk11, so I choose to use the first method  

TypeError: Failed to execute ‘fetch‘ on ‘Window‘: Request with GET/HEAD method cannot have body.

Swagger error:

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

reason:

The @ ResponseBody is used. Because the get method is declared in the method, the @ requestbody is used  
Get cannot get parameters using.

solve:

Getmapping   Change to postmapping

Idea unified setting code to UTF-8 code and solution of Tomcat garbled code

Modify project space code

File-> Settings-> Editor-> File encodings
check the bottom box

Modifying the relevant configuration in Tomcat

Step 1: modify Tomcat configuration file and add UTF-8 code

Change the service.xml configuration in Tomcat's conf folder to add URIEncoding="UTF-8", as follows.

<Connector port="8080" protocol="HTTP/1.1" ​ connectionTimeout="20000" ​ redirectPort="8443" URIEncoding="UTF-8"/>

It was found that the start-up condition remained unchanged

Step 2: change the idea configuration and set the encoding to UTF-8

Refer to the above method

Step 3: modify the parameters in logging. Properties under conf of Tomcat

Change java.util.logging.ConsoleHandler.encoding = GBK

to

java.util.logging.ConsoleHandler.encoding = UTF-8

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