You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

简易SpringBoot应用在Eclipse可运行,Unix终端启动抛异常如何解决

Hey there! Let's troubleshoot this step by step—since it works in Eclipse, the issue is almost definitely related to how you're building/running it in the Unix terminal. Here are the most common fixes to get your app up and running:

1. First, Ensure You've Built the App Correctly with Gradle

Eclipse handles builds behind the scenes, but in the terminal you need to explicitly build the executable JAR that includes all dependencies. Run these commands from your project root directory:

  • Clean any leftover build artifacts: ./gradlew clean
  • Build the full executable JAR (this is the key command for Spring Boot apps): ./gradlew bootJar

    Note: If you're using an older Spring Boot version (pre-2.x), you might need ./gradlew build instead, but bootJar is the standard for modern versions.

  • After the build finishes, your JAR file will live in the build/libs/ directory. Look for a file named like your-app-name-0.0.1-SNAPSHOT.jar—the exact name depends on the group and version settings in your build.gradle.
2. Run the Executable JAR Correctly

Once you have the built JAR, launch it with the standard java -jar command:

java -jar build/libs/your-app-name-0.0.1-SNAPSHOT.jar
  • Double-check the path and filename—typos here are super common! If you get a "file not found" error, navigate to build/libs/ with cd build/libs and list the files with ls to confirm the JAR exists.
3. Fix JDK Version Mismatches

Eclipse might be using a different JDK than your Unix terminal, which can cause runtime errors. Let's verify:

  • In your terminal, run java -version and javac -version to see what JDK is active.
  • In Eclipse, go to Window > Preferences > Java > Installed JREs to check which JDK it's using.
    Make sure both are using the same major version (e.g., Java 17 for Spring Boot 3.x, Java 8 or 11 for Spring Boot 2.x). If they don't match, set your terminal's JAVA_HOME environment variable to point to Eclipse's JDK, or install the correct version on your Unix machine.
4. Verify Your build.gradle Configuration

Double-check that your build.gradle has the necessary Spring Boot plugin to create an executable JAR. Here's a minimal working example for reference:

plugins {
    id 'org.springframework.boot' version '3.2.0'
    id 'io.spring.dependency-management' version '1.1.4'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '17'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}
  • If the Spring Boot plugin is missing, add it—without it, the JAR won't be configured to run as a standalone Spring Boot app.
5. Check File Permissions

If you get a "permission denied" error, make sure you have read access to the JAR file. Fix this with:

chmod +r build/libs/your-app-name-0.0.1-SNAPSHOT.jar

(You don't need execute permissions here since we're running the JAR via the Java runtime, but read access is mandatory.)

6. Dig Into the Exact Error Message

If none of the above works, share the full error output from the terminal. Common issues we can spot include missing dependencies (if you didn't use bootJar), classpath conflicts, or configuration errors that only surface in a standalone runtime.

内容的提问来源于stack exchange,提问作者nagy.zsolt.hun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:06:02