我正在构建一个 Java 应用程序,目的是将来将其打包为 Windows 可执行文件。我的 NetBeans 项目结构可以在这里看到 。 我目前正在使用 getResourceAsStream() 读取 config.properties。我不知道不能以类似的方式写入该文件。有人能建议一种实现此目标的方法吗?或者是否需要采用不同的方法来解决我的问题?谢谢。
我正在努力将我的项目从 Java 8 迁移到 Java 11。所以我使用了 Spring 5.1.0、Java 11、Eclipse 4.16 和 Tomcat 9。我能够成功构建源代码。但当谈到测试时,他们却失败了。
这是我在 pom.xml 中进行测试的内容。
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.27.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的测试用例在 Java 8 中的上述依赖关系下运行得非常好。但是当我将代码迁移到 Java 11 时,我遇到了以下异常。
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing
TestExecutionListener
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener@54e063d] to
prepare test instance [com.test.SomeTest2@4293943]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DefaultTestCDependencyInjectionTestExecutionListenerontext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DefaDefaultTestCDependencyInjectionTestExecutionListenerontextultTestContext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at …Run Code Online (Sandbox Code Playgroud) 我正在编写一个用于赋值的静态分析工具,它使用ASM库分析Java字节码.我们使用的ASM的一个部分需要(或者至少似乎要求)从ClassLoader加载该类.
我们希望该工具能够分析.class文件,而不需要它们在类路径上.我们已经在运行时从指定目录加载.classes并使用InputStream读取它们.在大多数情况下,这对于ASM是可接受的.有些类,例如SimpleVerifier,尝试加载类.
在这种情况下,是否可以注册要加载的.class文件,以便调用Class.forName()将加载它们?或者是否有一种简单的方法来扩展ClassLoader以允许它?
编辑:URLClassLoader有用的信息.不幸的是,使用Thread.currentThread().setContextClassLoader()它的实例在这种情况下不起作用.我正在调用的库代码使用它在实例初始化时检索的加载器getClass().getClassLoader().
当我设置URLClassLoader时,该类尚未初始化,所以我猜contextClassLoader不加载该类.
我是否正确理解了答案?是否可以使用URLClassLoader加载第三方类?
我在第7页的Windows 7机器上遇到了"Programming Clojure".将"examples"目录下载到"C:/ clojure"后,我键入:
用户>(要求'examples.introduction)
我得到了
; 评价中止.
java.io.FileNotFoundException:无法在类路径上找到examples/introduction__init.class或examples/introduction.clj:(NO_SOURCE_FILE:0)
我的.emacs文件如下所示:
(setq swank-clojure-extra-classpaths(list"C:/ Clojure"))
C:/ Clojure中的文件在那里(我triplechecked)
任何帮助将不胜感激.
我需要将类路径中存在的xml文件加载到我的java应用程序中.任何人都可以对此提出建议.
谢谢,
Narendra
我已经为R构建了一个包,它将R包装在一些Java类中.在我的开发笔记本电脑(Ubuntu)上,这个软件包加载正常,效果很好.在另外两台机器(一台Ubuntu,一台Debian)上,我试图使用这个包,并且.jpackage()调用没有设置类路径.
所有三台机器都运行R 2.12.1和rJava .8-8,我认为这是最新的.
整个软件包都在谷歌代码上,但这里是zzz.R文件的内容,它用于在一台机器上设置类路径,但不在其他机器上设置类路径:
##' @import rJava
.onLoad <- function(lib, pkg) {
pathToSdk <- paste(system.file(package = "GSRadR") , "/gsrad_sample/lib/", sep="")
jarPaths <- c(paste(pathToSdk, "clima_core-1.0.0.jar", sep=""),
paste(pathToSdk, "clima_GSRAD-1.0.0.jar", sep=""),
paste(pathToSdk, "colt-1.0.jar", sep=""),
paste(pathToSdk, "commons-lang-2.0.jar", sep=""),
paste(pathToSdk, "junit-3.8.1.jar", sep=""),
paste(pathToSdk, "log4j-1.2.8.jar", sep=""),
paste(pathToSdk, "xqore.jar", sep="")
)
.jpackage(pkg, morePaths=jarPaths)
attach( javaImport( c("java.lang", "java.io")))
packageStartupMessage( paste( "GSRadR loaded. The classpath is: ", paste(.jclassPath(), collapse=" " ) ) )
}
Run Code Online (Sandbox Code Playgroud)
在我的笔记本电脑上返回以下内容:
> require(GSRadR)
Loading required package: GSRadR
Loading required package: …Run Code Online (Sandbox Code Playgroud) 我不确定这意味着什么,我在.classpath中看到它
(我知道这与我如何在CCP应用程序中嵌入Clojure相关,但该线程已经过时,我的设置有所不同)
我正在使用Eclipse 3.7.1,现在已经尝试在Clojure中编写Eclipse/RCP应用程序(尽可能多).我已经尝试构建clojure.osgi和CCW的源代码版本,尝试了RCPClojure演示项目和其他一些东西.他们每个人都没有工作(主要看似"不可修复"的构建/类路径错误,缺乏最新的文档/响应,版本冲突等...)
我自己的步骤为我带来至少50%的成功:
创建一个包含Clojure 1.3.0 jar文件的新插件项目,设置插件ID org.clojure.v1.3.0
org.cljtest42使用RCP Hello模板创建一个新的插件项目
org.clojure插件依赖项/classes文件夹plugin.xml以将/classes文件夹添加到运行时类路径,也添加org.cljtest42到导出的包.在org.cljtest42包/命名空间中添加两个简单的Clojure文件:
TestClass.clj:
(ns org.cljtest42.TestClass
(:gen-class))
(defn -main [greet] (println greet))
Run Code Online (Sandbox Code Playgroud)
compile.clj
(ns org.cljtest42.compile)
(dorun (map compile ['org.cljtest42.TestClass]))
Run Code Online (Sandbox Code Playgroud)通过选择项目节点触发AOT编译,然后选择Run> Clojure application(该/classes文件夹现在应填充已编译的clojure类).
从Activator类中引用TestClass (例如在start()中 - 也在Perspective.createInitialLayout()中尝试过)
到现在为止还挺好.但是,尝试将此项目作为Eclipse应用程序运行始终会失败:
java.io.FileNotFoundException: Could not locate org/cljtest42/TestClass__init.class or org/cljtest42/TestClass.clj on classpath:
at clojure.lang.RT.load(RT.java:430)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385) …Run Code Online (Sandbox Code Playgroud) 如何将JAR文件包含(不仅仅是引用)到现有项目中?我通过使用项目属性添加它 - 构建路径 - 添加外部jar.但是当我导出我的项目,然后将其导入另一台计算机时,这个库就丢失了.
根据文档,泽西客户端需要的只是jersey-bundle.jar.但是简单的代码,构建请求并发送它会抛出异常.
java.lang.ClassNotFoundException: javax.ws.rs.ext.Providers
Run Code Online (Sandbox Code Playgroud)
添加jsr311-api-1.0.jar到classpath后.我有另一个例外.
java.lang.NoClassDefFoundError: javax/ws/rs/core/Response$StatusType
Run Code Online (Sandbox Code Playgroud)
我可以在哪里找到Jersey的完整依赖列表.应该包括什么罐子.顺便说一句,我不能用Maven,Ivy等.
谢谢