mvn exec:java 报错说找不到类?

CTF-Java-Gadget-master>mvn exec:java -Dexec.classpathScope=compile -Dexec.mainClass="com.xiinnn.commonly.POJOJackson"
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.xiinnn:CTF-Java-Gadget >---------------------
[INFO] Building CTF-Java-Gadget 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec:3.5.0:java (default-cli) @ CTF-Java-Gadget ---
[WARNING]
javassist.NotFoundException: com.fasterxml.jackson.databind.node.BaseJsonNode
    at javassist.ClassPool.get (ClassPool.java:430)
    at com.xiinnn.commonly.POJOJackson.main (POJOJackson.java:32)
    at org.codehaus.mojo.exec.ExecJavaMojo.doMain (ExecJavaMojo.java:375)
    at org.codehaus.mojo.exec.ExecJavaMojo.doExec (ExecJavaMojo.java:364)
    at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0 (ExecJavaMojo.java:286)
    at java.lang.Thread.run (Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.476 s
[INFO] Finished at: 2024-11-17T23:17:10+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.5.0:java (default-cli) on project CTF-Java-Gadget: An exception occurred while executing the Java class. com.fasterxml.jackson.databind.node.BaseJsonNode -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

使用 -X 输出下详细信息

mvn-X exec:java -Dexec.classpathScope=compile -Dexec.mainClass="com.xiinnn.commonly.POJOJackson"

[DEBUG]   (f) pluginDependencies = [org.codehaus.mojo:exec-maven-plugin:maven-plugin:3.5.0:, org.apache.maven.resolver:maven-resolver-util:jar:1.4.1:compile, org.apache.maven.resolver:maven-resolver-api:jar:1.4.1:compile, org.codehaus.plexus:plexus-utils:jar:4.0.2:compile, org.codehaus.plexus:plexus-xml:jar:3.0.1:compile, org.apache.commons:commons-exec:jar:1.4.0:compile, org.ow2.asm:asm:jar:9.7.1:compile, org.ow2.asm:asm-commons:jar:9.7.1:compile, org.ow2.asm:asm-tree:jar:9.7.1:compile]
[DEBUG]   (f) preloadCommonPool = 0
[DEBUG]   (f) project = MavenProject: com.xiinnn:CTF-Java-Gadget:1.0-SNAPSHOT @ D:\wgf\My Documents\GitHub\blog\text\docs\ctf\scripts\web\java\CTF-Java-Gadget-master\pom.xml
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@226b143b
[DEBUG]   (f) skip = false
[DEBUG]   (f) stopUnresponsiveDaemonThreads = false
[DEBUG] -- end configuration --
[DEBUG] Invoking : com.xiinnn.commonly.POJOJackson.main()
[DEBUG] Plugin Dependencies will be excluded.
[DEBUG] Project Dependencies will be included.
[DEBUG] Collected project artifacts [org.javassist:javassist:jar:3.27.0-GA:compile, com.fasterxml.jackson.core:jackson-databind:jar:2.14.1:compile, com.fasterxml.jackson.core:jackson-annotations:jar:2.14.1:compile, com.fasterxml.jackson.core:jackson-core:jar:2.14.1:compile, org.springframework:spring-aop:jar:5.3.24:compile, org.springframework:spring-beans:jar:5.3.24:compile, org.springframework:spring-core:jar:5.3.24:compile, org.springframework:spring-jcl:jar:5.3.24:compile, commons-collections:commons-collections:jar:3.2.1:compile, commons-beanutils:commons-beanutils:jar:1.9.3:compile, commons-logging:commons-logging:jar:1.2:compile, rome:rome:jar:1.0:compile, jdom:jdom:jar:1.0:compile, com.alibaba:fastjson:jar:1.2.80:compile, org.springframework:spring-webmvc:jar:5.3.24:compile, org.springframework:spring-context:jar:5.3.24:compile, org.springframework:spring-expression:jar:5.3.24:compile, org.springframework:spring-web:jar:5.3.24:compile, javax.servlet:javax.servlet-api:jar:4.0.1:compile, org.springframework:spring-tx:jar:3.1.0.RELEASE:compile, aopalliance:aopalliance:jar:1.0:compile, javax.transaction:jta:jar:1.1:compile]
[DEBUG] Collected project classpath [D:\wgf\My Documents\GitHub\blog\text\docs\ctf\scripts\web\java\CTF-Java-Gadget-master\target\classes]
[DEBUG] Adding to classpath : D:\wgf\My Documents\GitHub\blog\text\docs\ctf\scripts\web\java\CTF-Java-Gadget-master\target\classes
[DEBUG] Adding project dependency artifact: javassist to classpath
[DEBUG] Adding project dependency artifact: jackson-databind to classpath
[DEBUG] Adding project dependency artifact: jackson-annotations to classpath
[DEBUG] Adding project dependency artifact: jackson-core to classpath
[DEBUG] Adding project dependency artifact: spring-aop to classpath
[DEBUG] Adding project dependency artifact: spring-beans to classpath
[DEBUG] Adding project dependency artifact: spring-core to classpath
[DEBUG] Adding project dependency artifact: spring-jcl to classpath
[DEBUG] Adding project dependency artifact: commons-collections to classpath
[DEBUG] Adding project dependency artifact: commons-beanutils to classpath
[DEBUG] Adding project dependency artifact: commons-logging to classpath
[DEBUG] Adding project dependency artifact: rome to classpath
[DEBUG] Adding project dependency artifact: jdom to classpath
[DEBUG] Adding project dependency artifact: fastjson to classpath
[DEBUG] Adding project dependency artifact: spring-webmvc to classpath
[DEBUG] Adding project dependency artifact: spring-context to classpath
[DEBUG] Adding project dependency artifact: spring-expression to classpath
[DEBUG] Adding project dependency artifact: spring-web to classpath
[DEBUG] Adding project dependency artifact: javax.servlet-api to classpath
[DEBUG] Adding project dependency artifact: spring-tx to classpath
[DEBUG] Adding project dependency artifact: aopalliance to classpath
[DEBUG] Adding project dependency artifact: jta to classpath
[DEBUG] joining on thread Thread[com.xiinnn.commonly.POJOJackson.main(),5,com.xiinnn.commonly.POJOJackson]
[WARNING]
javassist.NotFoundException: com.fasterxml.jackson.databind.node.BaseJsonNode
    at javassist.ClassPool.get (ClassPool.java:430)
    at com.xiinnn.commonly.POJOJackson.main (POJOJackson.java:32)
    at org.codehaus.mojo.exec.ExecJavaMojo.doMain (ExecJavaMojo.java:375)
    at org.codehaus.mojo.exec.ExecJavaMojo.doExec (ExecJavaMojo.java:364)
    at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0 (ExecJavaMojo.java:286)
    at java.lang.Thread.run (Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.525 s
[INFO] Finished at: 2024-11-17T23:15:38+08:00
[INFO] ------------------------------------------------------------------------

我看这明细不是已经Adding project dependency artifact: jackson-databind to classpath。为什么还报找不到。

pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xiinnn</groupId>
    <artifactId>CTF-Java-Gadget</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
<!--        javassist用于更方面构造类-->
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.27.0-GA</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.14.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <dependency>
            <groupId>rome</groupId>
            <artifactId>rome</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.80</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

<!--        JTAReadObject2JNDI -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>

</project>

手动执行命令正常

java -Dfile.encoding=UTF-8 -classpath "D:\Program Files\Java\jdk1.8.0_73\jre\lib\rt.jar;.;%userprofile%\.m2\repository\org\javassist\javassist\3.27.0-GA\javassist-3.27.0-GA.jar;%userprofile%\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.14.1\jackson-databind-2.14.1.jar;%userprofile%\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.1\jackson-annotations-2.14.1.jar;%userprofile%\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.14.1\jackson-core-2.14.1.jar;%userprofile%\.m2\repository\org\springframework\spring-aop\5.3.24\spring-aop-5.3.24.jar;%userprofile%\.m2\repository\org\springframework\spring-beans\5.3.24\spring-beans-5.3.24.jar;%userprofile%\.m2\repository\org\springframework\spring-core\5.3.24\spring-core-5.3.24.jar;%userprofile%\.m2\repository\org\springframework\spring-jcl\5.3.24\spring-jcl-5.3.24.jar;%userprofile%\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;%userprofile%\.m2\repository\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;%userprofile%\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;%userprofile%\.m2\repository\rome\rome\1.0\rome-1.0.jar;%userprofile%\.m2\repository\jdom\jdom\1.0\jdom-1.0.jar;%userprofile%\.m2\repository\com\alibaba\fastjson\1.2.80\fastjson-1.2.80.jar;%userprofile%\.m2\repository\org\springframework\spring-webmvc\5.3.24\spring-webmvc-5.3.24.jar;%userprofile%\.m2\repository\org\springframework\spring-context\5.3.24\spring-context-5.3.24.jar;%userprofile%\.m2\repository\org\springframework\spring-expression\5.3.24\spring-expression-5.3.24.jar;%userprofile%\.m2\repository\org\springframework\spring-web\5.3.24\spring-web-5.3.24.jar;%userprofile%\.m2\repository\javax\servlet\javax.servlet-api\4.0.1\javax.servlet-api-4.0.1.jar;%userprofile%\.m2\repository\org\springframework\spring-tx\3.1.0.RELEASE\spring-tx-3.1.0.RELEASE.jar;%userprofile%\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;%userprofile%\.m2\repository\javax\transaction\jta\1.1\jta-1.1.jar" com.xiinnn.commonly.POJOJackson

输出classpath 对比

mvn:

C:\Users\IBM\.m2\repository\org\javassist\javassist\3.27.0-GA\javassist-3.27.0-GA.jar
C:\Users\IBM\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.14.1\jackson-databind-2.14.1.jar
C:\Users\IBM\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.1\jackson-annotations-2.14.1.jar
C:\Users\IBM\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.14.1\jackson-core-2.14.1.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-aop\5.3.24\spring-aop-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-beans\5.3.24\spring-beans-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-core\5.3.24\spring-core-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-jcl\5.3.24\spring-jcl-5.3.24.jar
C:\Users\IBM\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar
C:\Users\IBM\.m2\repository\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar
C:\Users\IBM\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
C:\Users\IBM\.m2\repository\rome\rome\1.0\rome-1.0.jar
C:\Users\IBM\.m2\repository\jdom\jdom\1.0\jdom-1.0.jar
C:\Users\IBM\.m2\repository\com\alibaba\fastjson\1.2.80\fastjson-1.2.80.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-webmvc\5.3.24\spring-webmvc-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-context\5.3.24\spring-context-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-expression\5.3.24\spring-expression-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-web\5.3.24\spring-web-5.3.24.jar
C:\Users\IBM\.m2\repository\javax\servlet\javax.servlet-api\4.0.1\javax.servlet-api-4.0.1.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-tx\3.1.0.RELEASE\spring-tx-3.1.0.RELEASE.jar
C:\Users\IBM\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar
C:\Users\IBM\.m2\repository\javax\transaction\jta\1.1\jta-1.1.jar

idea

D:\Program Files\Java\jdk1.8.0_73\jre\lib\charsets.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\deploy.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\access-bridge-64.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\cldrdata.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\dnsns.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\jaccess.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\jfxrt.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\localedata.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\nashorn.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunec.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunjce_provider.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunmscapi.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunpkcs11.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\zipfs.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\javaws.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jce.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jfr.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jfxswt.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jsse.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\management-agent.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\plugin.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\resources.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\rt.jar
G:\f2\src3\target\classes
C:\Users\IBM\.m2\repository\org\javassist\javassist\3.27.0-GA\javassist-3.27.0-GA.jar
C:\Users\IBM\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.14.1\jackson-databind-2.14.1.jar
C:\Users\IBM\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.1\jackson-annotations-2.14.1.jar
C:\Users\IBM\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.14.1\jackson-core-2.14.1.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-aop\5.3.24\spring-aop-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-beans\5.3.24\spring-beans-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-core\5.3.24\spring-core-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-jcl\5.3.24\spring-jcl-5.3.24.jar
C:\Users\IBM\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar
C:\Users\IBM\.m2\repository\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar
C:\Users\IBM\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
C:\Users\IBM\.m2\repository\rome\rome\1.0\rome-1.0.jar
C:\Users\IBM\.m2\repository\jdom\jdom\1.0\jdom-1.0.jar
C:\Users\IBM\.m2\repository\com\alibaba\fastjson\1.2.80\fastjson-1.2.80.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-webmvc\5.3.24\spring-webmvc-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-context\5.3.24\spring-context-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-expression\5.3.24\spring-expression-5.3.24.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-web\5.3.24\spring-web-5.3.24.jar
C:\Users\IBM\.m2\repository\javax\servlet\javax.servlet-api\4.0.1\javax.servlet-api-4.0.1.jar
C:\Users\IBM\.m2\repository\org\springframework\spring-tx\3.1.0.RELEASE\spring-tx-3.1.0.RELEASE.jar
C:\Users\IBM\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar
C:\Users\IBM\.m2\repository\javax\transaction\jta\1.1\jta-1.1.jar

发现mvn缺少了以下路径

D:\Program Files\Java\jdk1.8.0_73\jre\lib\charsets.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\deploy.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\access-bridge-64.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\cldrdata.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\dnsns.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\jaccess.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\jfxrt.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\localedata.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\nashorn.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunec.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunjce_provider.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunmscapi.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\sunpkcs11.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\zipfs.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\javaws.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jce.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jfr.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jfxswt.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\jsse.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\management-agent.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\plugin.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\resources.jar
D:\Program Files\Java\jdk1.8.0_73\jre\lib\rt.jar
G:\f2\src3\target\classes

2024年11月18日11:55:39 POM 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xiinnn</groupId>
    <artifactId>CTF-Java-Gadget</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!--        javassist用于更方面构造类-->
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.27.0-GA</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.14.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <dependency>
            <groupId>rome</groupId>
            <artifactId>rome</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.80</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

        <!--        JTAReadObject2JNDI -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                    <mainClass>com.xiinnn.commonly.POJOJackson</mainClass>
                    <classpathScope>compile</classpathScope>
                    <!-- 确保使用项目的完整依赖路径 -->
                    <additionalClasspathElements>
                        <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
                        <additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement>
                    </additionalClasspathElements>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
阅读 494
avatarAI BotBETA

答案

这个错误发生的原因可能是 jackson-databind 库没有被正确地加载或者类路径(classpath)中存在冲突。尽管 Maven 在调试输出中显示已经添加了 jackson-databind 到类路径中,但仍然出现了 javassist.NotFoundException,这通常表示在运行时无法找到指定的类。

可能的解决方案包括:

  1. 检查 jackson-databind 的版本
    确保项目中使用的 jackson-databind 版本与代码中引用的版本一致。有时候,如果项目中包含了多个版本的同一个库,可能会导致类加载问题。
  2. 检查项目的依赖树
    使用 mvn dependency:tree 命令来查看项目的依赖树,检查是否有其他依赖间接引入了不同版本的 jackson-databind
  3. 清理和重新构建项目
    有时候,简单的清理和重新构建项目可以解决类路径问题。可以尝试运行 mvn clean install
  4. 检查 Maven 配置
    确保 pom.xml 文件中的配置正确无误,特别是关于依赖和插件的部分。
  5. 确保没有类加载器问题
    如果你的应用使用了复杂的类加载器机制(例如在 Web 容器中运行),确保 jackson-databind 类可以被正确加载。
  6. 使用 -e-X 选项重新运行 Maven
    使用更详细的输出选项来重新运行 Maven,可能会提供更多关于问题的线索。
mvn exec:java -Dexec.classpathScope=compile -Dexec.mainClass="com.xiinnn.commonly.POJOJackson" -e -X

通过这些步骤,你应该能够诊断并解决这个问题。如果问题仍然存在,可能需要更深入地检查代码和配置。

1 个回答

我提供一下我的POM文件,你可以对比一下

POM文件

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xiinnn</groupId>
    <artifactId>CTF-Java-Gadget</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- javassist用于更方便构造类 -->
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.27.0-GA</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.14.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <dependency>
            <groupId>rome</groupId>
            <artifactId>rome</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.80</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

        <!-- JTAReadObject2JNDI -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                    <mainClass>com.xiinnn.commonly.POJOJackson</mainClass>
                    <classpathScope>compile</classpathScope>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
                        <additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement>
                    </additionalClasspathElements>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  1. 在你的 pom.xml 文件中添加或更新上述依赖项
  2. 开发过程使用mvn clean compile验证编译是否通过
  3. 如果第二步验证正通过准备发布或需要完整构建时:使用 mvn clean install
  4. 然后再次运行你的命令:

    mvn exec:java -Dexec.classpathScope=compile -Dexec.mainClass="com.xiinnn.commonly.POJOJackson"

补充

使用 LoaderClassPath 方法,确保 javassist 使用当前线程的类加载器来查找类路径,这样可以更好地处理依赖关系。以下是具体的代码示例:

ClassPool classPool = ClassPool.getDefault();
classPool.appendClassPath(new LoaderClassPath(Thread.currentThread().getContextClassLoader()));
CtClass ctClass = classPool.get("com.fasterxml.jackson.databind.node.BaseJsonNode");

可以将这段代码添加到你项目的主类或需要使用 javassist 的类中。假设你有一个主类 Main,你可以在 main 方法中添加这段代码。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏