有一个明确的解决方案,可以使用插件test-jar
目标在maven项目之间共享通用测试代码maven-jar-plugin
(参见此处).
我需要对测试资源做类似的事情,特别是,我希望项目A的测试资源在测试期间在项目B的类路径中可用.
对于项目A,需要声明:
<!-- Package and attach test resources to the list of artifacts: -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<jar destfile="${project.build.directory}/test-resources.jar">
<fileset dir="${project.basedir}/test-resources" />
</jar>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/test-resources.jar</file>
<type>jar</type>
<classifier>test-resources</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在项目B中,它将是正常依赖:
<dependency>
<groupId>myproject.groupId</groupId>
<artifactId>myartifact</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>test-resources</classifier>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
问题:它应该适用于所有情况吗?是否可以打包资源maven-antrun-plugin
(使用更多'轻量级'插件)?
什么是纯Java HTML查看器和渲染器?要求是:
JComponent
放置在Scrollable
窗格中的接口.我只知道一些组件和项目,其中一些现在已经不存在了:
JEditorPane
,支持HTML 3.2(自Java 1.4起)javax.swing.text.html.HTMLEditorKit
)JWebPane
(它是否曾被发布)?考虑以下情况:
有一个序列化文件,由旧版本的应用程序创建.不幸的是,已经序列化了类的包已更改.现在我需要将此文件中的信息加载到同一个类中,但位于不同的包中.此类已serialVersionUID
定义且未更改(即兼容).
问题:是否可以使用任何技巧从该文件加载新的类实例(除了将类复制到旧包中然后使用反序列化包装器逻辑)?可以用来readResolve()
从移动/重命名类中恢复吗?如果没有,请解释原因.
假设我有一个服务器GET
请求并返回要序列化为JSON的bean,并且还提供了一个异常处理程序IllegalArgumentException
,可以在服务中引发:
@RequestMapping(value = "/meta/{itemId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public MetaInformation getMetaInformation(@PathVariable int itemId) {
return myService.getMetaInformation(itemId);
}
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public String handleIllegalArgumentException(IllegalArgumentException ex) {
return ExceptionUtils.getStackTrace(ex);
}
Run Code Online (Sandbox Code Playgroud)
消息转换器是:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
Run Code Online (Sandbox Code Playgroud)
现在,当我在浏览器中请求给定的URL时,我看到了正确的JSON回复.但是,如果引发异常,则字符串化的异常也会转换为JSON,但我希望它能被处理StringHttpMessageConverter
(产生的text/plain
mime类型).我该怎么办?
为了使图片更完整(和复杂),假设我还有以下处理程序:
@RequestMapping(value = "/version", method = RequestMethod.GET)
@ResponseBody
public String getApplicationVersion() {
return "1.0.12";
}
Run Code Online (Sandbox Code Playgroud)
此处理程序允许返回字符串由两者序列化MappingJackson2HttpMessageConverter
并StringHttpMessageConverter
依赖于Accept-type
客户端传递.返回类型和值应如下所示:
+----+---------------------+-----------------------+------------------+-------------------------------------+ | NN | URL …
在我的Makefile中,我想检查以下复杂情况:
ifdef VAR1 || VAR2 || VAR3
action
endif
Run Code Online (Sandbox Code Playgroud)
但文档说不支持这样的语法.因此,我想到的唯一简单的解决方法是使用串联:
ifneq ($(VAR1)$(VAR2)$(VAR3),)
action
endif
Run Code Online (Sandbox Code Playgroud)
还有其他更正确的解决方案吗?
对于以下情况:
ifdef VAR1 && VAR2 && VAR3
action
endif
Run Code Online (Sandbox Code Playgroud)
一个人需要写
ifdef VAR1
ifdef VAR2
ifdef VAR3
action
endif
endif
endif
Run Code Online (Sandbox Code Playgroud)
这也很难看.还有更优雅的选择吗?
我有以下递归makefile:
.PHONY: all clean
%.subdir:
$(MAKE) -C src $*
$(MAKE) -C dict $*
all: all.subdir
clean: clean.subdir
Run Code Online (Sandbox Code Playgroud)
它工作正常:
$ make all
make -C src all
make[1]: Entering directory `/or-1.3.6-fix/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/or-1.3.6-fix/src'
make -C dict all
make[1]: Entering directory `/or-1.3.6-fix/dict'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/or-1.3.6-fix/dict'
Run Code Online (Sandbox Code Playgroud)
但将%.subdir
规则定义为虚假更合乎逻辑:
.PHONY: all clean all.subdir clean.subdir
Run Code Online (Sandbox Code Playgroud)
现在让我停止工作:
$ make all
make: Nothing to be done for `all'.
$ make …
Run Code Online (Sandbox Code Playgroud) 我想在Java程序中定义一个方法拦截器,换句话说我希望在每个方法调用中执行一个行为.此应用程序不在应用程序服务器中执行,因此我无法使用EJB调用拦截器.我在标准Java库中找到了一个很好的Proxy API,但它有限,因为它需要在代理创建中使用一个接口:
Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
new Class[] { Foo.class },
handler);
Run Code Online (Sandbox Code Playgroud)
是否有类似的API不强制将Foo.class声明为接口?
如果Maven大师社区可以帮助我完成以下任务,那将是很棒的.
我想以一种方式自动化Hudson中Maven模块的发布过程,即发布过程以批处理模式运行(不需要从控制台询问任何内容).目前我使用常见步骤release:prepare
(<preparationGoals>versions:update-parent clean verify</preparationGoals>
在提交之前将父更新到最新版本)+ release:perform
.不过我希望Maven能够做到以下几点:
有些人在准备步骤中:
groupId
与当前模块和父模块匹配的所有依赖项,请替换-SNAPSHOT
为已发布的版本(例如versions:use-releases -Dincludes=???
).发布后的一些内容:
groupId
与当前模块和父模块匹配的所有依赖项,将版本替换为-SNAPSHOT
版本(例如versions:use-latest-snapshots ...
).例:
<parent>
<groupId>org.mycompany.myproject</groupId>
<artifactId>myproject-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myproject-api</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在标记模块之前转换为:
<parent>
<groupId>org.mycompany.myproject</groupId>
<artifactId>myproject-parent</artifactId>
<version>1.0</version>
</parent>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myproject-api</artifactId>
<version>1.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在发布成功后转化为:
<parent>
<groupId>org.mycompany.myproject</groupId>
<artifactId>myproject-parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myproject-api</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我觉得它需要混合使用
versions:use-releases scm:commit release:prepare release:perform versions:use-latest-snapshots scm:commit
但我不确定这样做的最佳方法是什么.特别是尽可能减少提交是很好的:难度是reparationGoals
在-SNAPSHOT
版本检查后运行.
在某种意义上,所描述的项目不是一个多模块项目,因为父POM没有通过它来引用它的子项<modules>
.SCM结构如下: …
在Spring 3.2.5→4.0.0版本更新后尝试编译源时,我有奇怪的行为.
错误的代码片段ApplicationControllerTest.java
(它相当于文档中的代码):
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
...
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
Run Code Online (Sandbox Code Playgroud)
错误:
COMPILATION ERROR :
/C:/Development/.../war/src/test/java/org/.../web/controller/ApplicationControllerTest.java:[59,61] C:\Development\...\war\src\test\java\org\...\web\controller\ApplicationControllerTest.java:59: incompatible types; inferred type argument(s) java.lang.Object do not conform to bounds of type variable(s) B
found : <B>org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder<B>
required: java.lang.Object
如果人们查看MockMvcBuilders
来源,可以看出差异:
Spring 4.0.0:
public static <B extends DefaultMockMvcBuilder<B>> DefaultMockMvcBuilder<B> webAppContextSetup(WebApplicationContext context) {
return new DefaultMockMvcBuilder<B>(context);
}
Run Code Online (Sandbox Code Playgroud)
Spring 3.2.5:
public static …
Run Code Online (Sandbox Code Playgroud) java ×5
spring ×3
makefile ×2
html ×1
maven ×1
maven-2 ×1
mime-types ×1
reflection ×1
spring-4 ×1
spring-mvc ×1