0

今天早些时候,我发现自己在回答一个问题,该问题使用了一个我以前没有使用过的库(Choco 3.3.3)。当我测试我的代码以检查它是否有效时,我收到了一个异常,java.lang.NoClassDefFoundError. 为了解决这个问题,我尝试使用他们网站上的早期版本的库。我从他们的一个 zip 文件中提取的源代码编译了我自己的版本(有关构建信息,请参见下文),我什至从 git 下载并编译了它。然而,这些解决方案都没有奏效。

使用Choco提供的代码示例可以显示完全相同的异常。

import org.chocosolver.solver.Solver;
import org.chocosolver.solver.constraints.IntConstraintFactory;
import org.chocosolver.solver.search.strategy.IntStrategyFactory;
import org.chocosolver.solver.trace.Chatterbox;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.VariableFactory;

public class Test {
    public static void main(String[] args) {
        // 1. Create a Solver
        Solver solver = new Solver("my first problem");
        // 2. Create variables through the variable factory
        IntVar x = VariableFactory.bounded("X", 0, 5, solver);
        IntVar y = VariableFactory.bounded("Y", 0, 5, solver);
        // 3. Create and post constraints by using constraint factories
        solver.post(IntConstraintFactory.arithm(x, "+", y, "<", 5));
        // 4. Define the search strategy
        solver.set(IntStrategyFactory.lexico_LB(x, y));
        // 5. Indicates that all solutions should be print to the console
        Chatterbox.showSolutions(solver);
        // 6. Launch the resolution process
        solver.findSolution();
        // 7. Finally, outputs the resolution statistics
        Chatterbox.printStatistics(solver);
    }
}

有人能帮我解决这个问题吗?

有关更多信息,请参见下文

异常堆栈

这是我编译并运行代码时输出的内容

C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Stack Overflow\Answers\Choco equation value>javac -cp choco-solver-3.3.3.jar; Test.java

C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Stack Overflow\Answers\Choco equation value>java Test
Exception in thread "main" java.lang.NoClassDefFoundError: org/chocosolver/solver/Solver
        at Test.main(Test.java:11)
Caused by: java.lang.ClassNotFoundException: org.chocosolver.solver.Solver
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

Maven 构建信息

这是我尝试从源代码构建时输出的内容

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master>mvn clean package -DskipTests
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Choco-3.3.3: an Open-Source Constraint Solver
[INFO] org.choco-solver:choco-solver
[INFO] org.choco-solver:choco-samples
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Choco-3.3.3: an Open-Source Constraint Solver 3.3.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ choco ---
[INFO]
[INFO] --- maven-processor-plugin:3.1.0-beta1:process (process) @ choco ---
[INFO]
[INFO] >>> maven-source-plugin:2.4:jar (attach-sources) > generate-sources @ choco >>>
[INFO]
[INFO] --- maven-processor-plugin:3.1.0-beta1:process (process) @ choco ---
[INFO]
[INFO] <<< maven-source-plugin:2.4:jar (attach-sources) < generate-sources @ choco <<<
[INFO]
[INFO] --- maven-source-plugin:2.4:jar (attach-sources) @ choco ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building org.choco-solver:choco-solver 3.3.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ choco-solver ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.5.201505241946:prepare-agent (default) @ choco-solver ---
[INFO] argLine set to "-javaagent:C:\\Users\\Daniel\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.5.201505241946\\org.jacoco.age
nt-0.7.5.201505241946-runtime.jar=destfile=C:\\Users\\Daniel\\Dropbox\\Programming\\Code\\Notepad++\\Java\\Packages\\Choco\\choco sourc
e\\choco3-master\\choco-solver\\target\\jacoco.exec"
[INFO]
[INFO] --- maven-processor-plugin:3.1.0-beta1:process (process) @ choco-solver ---
[WARNING] No processors specified. Using default discovery mechanism.
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeBoolTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeDoubleTrail.java:34: warning: sun.misc.Unsafe is internal proprietary AP
I and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeIntTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API a
nd may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeLongTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.sisu.scanners.index.SisuInde
xAPT6' less than -source '1.8'
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeBoolTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeDoubleTrail.java:34: warning: sun.misc.Unsafe is internal proprietary AP
I and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeIntTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API a
nd may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeLongTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: warning: The following options were not recognized by any processor: '[myoption]'
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ choco-solver ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ choco-solver ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 598 source files to C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\
choco-solver\target\classes
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeBoolTrail.java:[34,16] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeIntTrail.java:[34,16] sun.misc.Unsafe is internal proprietary API and may be remove
d in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeDoubleTrail.java:[34,16] sun.misc.Unsafe is internal proprietary API and may be rem
oved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeLongTrail.java:[34,16] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeBoolTrail.java:[46,19] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeBoolTrail.java:[48,43] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeBoolTrail.java:[50,42] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeBoolTrail.java:[99,19] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeBoolTrail.java:[101,31] sun.misc.Unsafe is internal proprietary API and may be remo
ved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeBoolTrail.java:[103,21] sun.misc.Unsafe is internal proprietary API and may be remo
ved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeIntTrail.java:[46,19] sun.misc.Unsafe is internal proprietary API and may be remove
d in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeIntTrail.java:[48,43] sun.misc.Unsafe is internal proprietary API and may be remove
d in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeIntTrail.java:[50,42] sun.misc.Unsafe is internal proprietary API and may be remove
d in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeIntTrail.java:[99,19] sun.misc.Unsafe is internal proprietary API and may be remove
d in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeIntTrail.java:[101,31] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeIntTrail.java:[103,21] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeDoubleTrail.java:[46,19] sun.misc.Unsafe is internal proprietary API and may be rem
oved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeDoubleTrail.java:[48,43] sun.misc.Unsafe is internal proprietary API and may be rem
oved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeDoubleTrail.java:[50,42] sun.misc.Unsafe is internal proprietary API and may be rem
oved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeDoubleTrail.java:[99,19] sun.misc.Unsafe is internal proprietary API and may be rem
oved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeDoubleTrail.java:[101,31] sun.misc.Unsafe is internal proprietary API and may be re
moved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeDoubleTrail.java:[103,21] sun.misc.Unsafe is internal proprietary API and may be re
moved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeLongTrail.java:[46,19] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeLongTrail.java:[48,43] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeLongTrail.java:[50,42] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeLongTrail.java:[99,19] sun.misc.Unsafe is internal proprietary API and may be remov
ed in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeLongTrail.java:[101,31] sun.misc.Unsafe is internal proprietary API and may be remo
ved in a future release
[WARNING] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java
/org/chocosolver/memory/trailing/trail/unsafe/UnsafeLongTrail.java:[103,21] sun.misc.Unsafe is internal proprietary API and may be remo
ved in a future release
[INFO] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java/or
g/chocosolver/solver/search/loop/MoveBinaryDFS.java: Some input files use unchecked or unsafe operations.
[INFO] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/main/java/or
g/chocosolver/solver/search/loop/MoveBinaryDFS.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ choco-solver ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ choco-solver ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 105 source files to C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\
choco-solver\target\test-classes
[INFO] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/test/java/or
g/chocosolver/choco/strategy/StrategyTest.java: Some input files use unchecked or unsafe operations.
[INFO] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-solver/src/test/java/or
g/chocosolver/choco/strategy/StrategyTest.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-surefire-plugin:2.18:test (default-test) @ choco-solver ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.5.201505241946:report (report) @ choco-solver ---
[INFO] Skipping JaCoCo execution due to missing execution data file:C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Ch
oco\choco source\choco3-master\choco-solver\target\jacoco.exec
[INFO]
[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ choco-solver ---
[INFO] Building jar: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\tar
get\choco-solver-3.3.3.jar
[INFO]
[INFO] --- maven-assembly-plugin:2.5.2:single (make-assembly) @ choco-solver ---
[INFO] Reading assembly descriptor: src/assembly/with-dep.xml
[INFO] Building jar: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\tar
get\choco-solver-3.3.3-with-dependencies.jar
[INFO]
[INFO] >>> maven-source-plugin:2.4:jar (attach-sources) > generate-sources @ choco-solver >>>
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.5.201505241946:prepare-agent (default) @ choco-solver ---
[INFO] argLine set to "-javaagent:C:\\Users\\Daniel\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.5.201505241946\\org.jacoco.age
nt-0.7.5.201505241946-runtime.jar=destfile=C:\\Users\\Daniel\\Dropbox\\Programming\\Code\\Notepad++\\Java\\Packages\\Choco\\choco sourc
e\\choco3-master\\choco-solver\\target\\jacoco.exec"
[INFO]
[INFO] --- maven-processor-plugin:3.1.0-beta1:process (process) @ choco-solver ---
[WARNING] No processors specified. Using default discovery mechanism.
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeBoolTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeDoubleTrail.java:34: warning: sun.misc.Unsafe is internal proprietary AP
I and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeIntTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API a
nd may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeLongTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.sisu.scanners.index.SisuInde
xAPT6' less than -source '1.8'
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeBoolTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeDoubleTrail.java:34: warning: sun.misc.Unsafe is internal proprietary AP
I and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeIntTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API a
nd may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\sr
c\main\java\org\chocosolver\memory\trailing\trail\unsafe\UnsafeLongTrail.java:34: warning: sun.misc.Unsafe is internal proprietary API
and may be removed in a future release
import sun.misc.Unsafe;
               ^
[WARNING] diagnostic: warning: The following options were not recognized by any processor: '[myoption]'
[INFO]
[INFO] <<< maven-source-plugin:2.4:jar (attach-sources) < generate-sources @ choco-solver <<<
[INFO]
[INFO] --- maven-source-plugin:2.4:jar (attach-sources) @ choco-solver ---
[INFO] Building jar: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-solver\tar
get\choco-solver-3.3.3-sources.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building org.choco-solver:choco-samples 3.3.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ choco-samples ---
[INFO]
[INFO] --- maven-processor-plugin:3.1.0-beta1:process (process) @ choco-samples ---
[WARNING] No processors specified. Using default discovery mechanism.
[WARNING] diagnostic: warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.sisu.scanners.index.SisuInde
xAPT6' less than -source '1.8'
[WARNING] diagnostic: warning: The following options were not recognized by any processor: '[myoption]'
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ choco-samples ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-m
aster\choco-samples\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ choco-samples ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 81 source files to C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\c
hoco-samples\target\classes
[INFO] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-samples/src/main/java/o
rg/chocosolver/samples/AbstractBenchmarking.java: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\c
hoco3-master\choco-samples\src\main\java\org\chocosolver\samples\AbstractBenchmarking.java uses or overrides a deprecated API.
[INFO] /C:/Users/Daniel/Dropbox/Programming/Code/Notepad++/Java/Packages/Choco/choco source/choco3-master/choco-samples/src/main/java/o
rg/chocosolver/samples/AbstractBenchmarking.java: Recompile with -Xlint:deprecation for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ choco-samples ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-m
aster\choco-samples\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ choco-samples ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 21 source files to C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\c
hoco-samples\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18:test (default-test) @ choco-samples ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ choco-samples ---
[INFO] Building jar: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-samples\ta
rget\choco-samples-3.3.3.jar
[INFO]
[INFO] >>> maven-source-plugin:2.4:jar (attach-sources) > generate-sources @ choco-samples >>>
[INFO]
[INFO] --- maven-processor-plugin:3.1.0-beta1:process (process) @ choco-samples ---
[WARNING] No processors specified. Using default discovery mechanism.
[WARNING] diagnostic: warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.sisu.scanners.index.SisuInde
xAPT6' less than -source '1.8'
[WARNING] diagnostic: warning: The following options were not recognized by any processor: '[myoption]'
[INFO]
[INFO] <<< maven-source-plugin:2.4:jar (attach-sources) < generate-sources @ choco-samples <<<
[INFO]
[INFO] --- maven-source-plugin:2.4:jar (attach-sources) @ choco-samples ---
[INFO] Building jar: C:\Users\Daniel\Dropbox\Programming\Code\Notepad++\Java\Packages\Choco\choco source\choco3-master\choco-samples\ta
rget\choco-samples-3.3.3-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Choco-3.3.3: an Open-Source Constraint Solver ...... SUCCESS [  0.967 s]
[INFO] org.choco-solver:choco-solver ...................... SUCCESS [ 31.333 s]
[INFO] org.choco-solver:choco-samples ..................... SUCCESS [  8.174 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 40.617 s
[INFO] Finished at: 2016-01-11T19:21:09+00:00
[INFO] Final Memory: 42M/771M
[INFO] ------------------------------------------------------------------------
4

1 回答 1

1

您需要将命令行更改为:

java -classpath .;choco-solver-3.3.3.jar Test

即使这样做,您仍然没有所有依赖项:

Exception in thread "main" java.lang.NoClassDefFoundError: gnu/trove/map/hash/TIntObjectHashMap
        at org.chocosolver.solver.Solver.<init>(Solver.java:269)
        at org.chocosolver.solver.Solver.<init>(Solver.java:296)
        at Test.main(Test.java:11)
Caused by: java.lang.ClassNotFoundException: gnu.trove.map.hash.TIntObjectHashMap
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 3 more

所有依赖项列表:

dk.brics.automaton:automaton:1.11-8
args4j:args4j:2.32
org.javabits.jgrapht:jgrapht-core:0.9.3
net.sf.trove4j:trove4j:3.0.3
com.github.cp-profiler:cpprof-java:1.1.0
org.zeromq:jeromq:0.3.4
com.google.protobuf:protobuf-java:2.6.1

我建议您创建单独的 Maven 项目,添加choco-solver到您的 pom.xml 并构建您的 jar 文件。(Maven会自动下载所有依赖)

<dependency>
   <groupId>org.choco-solver</groupId>
   <artifactId>choco-solver</artifactId>
   <version>3.3.3</version>
</dependency>

来源:https ://github.com/chocoteam/choco3

于 2016-01-11T19:59:55.467 回答