Tag Archives: Upload Images error

[Solved] java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/ImageFormatException (Upload Images Error)

1. Problem phenomenon

upload image function, local test compilation needs to refer to the plug-in, otherwise the compilation does not pass.

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
<compilerArguments>
<verbose />
<bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>
<!–<bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>–>
</compilerArguments>
</configuration>

</plugin>
</plugins>
</build>
Then the local test passed, but the release to the test environment reported an error.org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/ImageFormatException

2. Reason

upload compressed images using the contents of the com.sun package, but the test environment with java openjdk, lib below the rt.jar without com/sun/image/codec/jpeg package, resulting in references to this class

3. Solution: Install the standard jdk

cd /etc

vim profile

export JAVA_HOME=/usr/local/jdk8
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$HOME/bin:$HOME/.local/bin:$PATH

source profile

java -version