任何人都可以告诉我如何强制maven在使用包路径自动生成的hibernate.cfg.xml文件中映射.hbm.xml文件之前?
我的一般想法是,我想通过maven使用hibernate-tools来为我的应用程序生成持久层.所以,我需要hibernate.cfg.xml,然后是所有my_table_names.hbm.xml,最后生成POJO.然而,hbm2java当我将*.hbm.xml文件放入src/main/resources/package/path/文件夹但hbm2cfgxml仅通过表名指定映射文件时,目标将无效,即:
<mapping resource="MyTableName.hbm.xml" />
Run Code Online (Sandbox Code Playgroud)
所以最大的问题是:我如何配置hbm2cfgxml以便hibernate.cfg.xml如下所示:
<mapping resource="package/path/MyTableName.hbm.xml" />
Run Code Online (Sandbox Code Playgroud)
我的pom.xml目前看起来像这样:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hbm2cfgxml</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2cfgxml</goal>
</goals>
<inherited>false</inherited>
<configuration>
<components>
<component>
<name>hbm2cfgxml</name>
<implemetation>jdbcconfiguration</implementation>
<outputDirectory>src/main/resources/</outputDirectory>
</component>
</components>
<componentProperties>
<packagename>package.path</packageName>
<configurationFile>src/main/resources/hibernate.cfg.xml</configurationFile>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
然后是第二个问题:有没有办法告诉maven在执行之前将资源复制到目标文件夹hbm2java?目前我正在使用
mvn clean resources:resources generate-sources
Run Code Online (Sandbox Code Playgroud)
为此,但必须有一个更好的方法.
谢谢你的帮助.
更新:
@Pascal:谢谢你的帮助.现在,映射的路径工作正常,但我不知道之前有什么问题.在从中读取数据库配置时,写入hibernate.cfg.xml可能存在一些问题(尽管文件已更新).
我删除了文件hibernate.cfg.xml,将其替换为database.properties并运行目标hbm2cfgxml和hbm2hbmxml.我还没有使用outputDirectory,也没有configurationfile在这些目标了.
结果,文件hibernate.cfg.xml和所有文件*.hbm.xml都生成到我的target/hibernate3/generated-mappings /文件夹中,这是默认值.然后我hbm2java用以下内容更新了目标:
<componentProperties>
<packagename>package.name</packagename>
<configurationfile>target/hibernate3/generated-mappings/hibernate.cfg.xml</configurationfile>
</componentProperties>
Run Code Online (Sandbox Code Playgroud)
但后来我得到以下内容: …
在我的项目中,我有一个顶级的抽象类FrameProducer.我在这个级别添加了一个slf4j记录器,因此每个继承类都已经拥有它.这里的代码:
public abstract class FrameProducer extends Observable {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
protected BufferedImage frame;
public BufferedImage getFrame() {
return frame;
}
public void fireEvent() {
logger.debug("Firing event. Implementing class: {}", this.getClass());
setChanged();
notifyObservers();
}
}
Run Code Online (Sandbox Code Playgroud)
还有两个继承类:CameraFrameGrabber和GrayscaleFilter.然而,当从该方法fireEvent()调用该方法CameraFrameGrabber或GrayscaleFilter在该FrameProducer级别记录该消息时.这里是日志,为清楚起见:
FrameProducer.fireEvent - Firing event. Implementing class: class com.ofj.frameaccess.CameraFrameGrabber
FrameProducer.fireEvent - Firing event. Implementing class: class com.ofj.frameaccess.GrayscaleFilter
Run Code Online (Sandbox Code Playgroud)
是否可以以FrameProducer一种方式初始化记录器,使得所有内容都记录在我的类层次结构中最专业的级别?
谢谢你的帮助.
编辑:我的log4j.properties看起来像这样:
log4j.rootCategory=TRACE, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=DEBUG
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout …Run Code Online (Sandbox Code Playgroud) 我在Java中重写的遗留软件使用自定义(类似于Win-1252)编码作为其数据存储.对于我正在构建的新系统,我想用UTF-8替换它.
所以我需要将这些文件转换为UTF-8来提供我的数据库.我知道使用的字符映射,但它不是任何广为人知的字符映射.例如."A"位于位置0x0041(如在Win-1252中),但在0x0042处有一个符号,其中UTF-8出现在位置0x0102上,依此类推.有没有一种简单的方法来解码和转换这些文件与Java?
我已经阅读了很多帖子,但它们都处理了某种行业标准编码,而不是自定义编码.我期望可以创建一个自定义java.nio.ByteBuffer.CharsetDecoder或java.nio.charset.Charset传递给它,java.io.InputStreamReader如第一个答案在这里所述?
欢迎任何建议.
我正在尝试hbm2java使用maven 配置生成POJO类和DAO对象.我正在处理的一个问题是没有生成包名.我正在使用以下pom:
<execution>
<id>hbm2java</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<inherited>false</inherited>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
</component>
</components>
<componentProperties>
<packagename>package.name</packagename>
<configurationfile>target/hibernate3/generated-mappings/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)
然而,生成的代码从以下开始:
// default package
// Generated 2010-05-17 13:11:51 by Hibernate Tools 3.2.2.GA
/**
* Messages generated by hbm2java
*/
public class Messages implements java.io.Serializable {
Run Code Online (Sandbox Code Playgroud)
有没有办法强制maven生成packagename中定义的包部分?
更新:
这是我的hibernate.cfg.xml,也是由hibernate-tools(hbm2cfgxml)自动生成的:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property …Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以配置hibernate3-maven-plugin为检测序列生成器primary-key?我正在使用一种自下而上的hibernate配置方法(这意味着让您在现有数据库架构上hibernate-tools使用a生成休眠配置)。我读过这个,而且这已经(这两个可能是不相关的,也可以留下一个提示)。我的如下:jdbc-connectionreverse-engineeringhibernate.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<table name="ORDERS">
<primary-key>
<!-- setting up a specific id generator for a table -->
<generator class="sequence">
<param name="sequence">ORDERS_ORDER_ID_seq</param>
</generator>
<key-column name="ORDER_ID"/>
</primary-key>
</table>
</hibernate-reverse-engineering>
Run Code Online (Sandbox Code Playgroud)
我期望它生成这样的Orders.hbm.xml文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2010-06-06 18:55:42 by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
<class name="some.package.Orders" table="orders" schema="public">
<id name="orderId" type="long">
<column …Run Code Online (Sandbox Code Playgroud) 我想用简单的颜色进行灰度转换java.awt.image.BufferedImage.我是图像处理领域的初学者,所以如果我感到困惑,请原谅.
我的输入图像是一个RGB 24位图像(没有alpha),我想BufferedImage在输出上获得一个8位灰度,这意味着我有一个这样的类(为清晰起见,省略了详细信息):
public class GrayscaleFilter {
private BufferedImage colorFrame;
private BufferedImage grayFrame =
new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经成功尝试了2种转换方法,首先是:
private BufferedImageOp grayscaleConv =
new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
protected void filter() {
grayscaleConv.filter(colorFrame, grayFrame);
}
Run Code Online (Sandbox Code Playgroud)
第二个是:
protected void filter() {
WritableRaster raster = grayFrame.getRaster();
for(int x = 0; x < raster.getWidth(); x++) {
for(int y = 0; y < raster.getHeight(); y++){
int argb = colorFrame.getRGB(x,y);
int r = (argb >> 16) & 0xff;
int g = (argb >> …Run Code Online (Sandbox Code Playgroud) 我编写了一个简单的测试程序,试图学习如何在C++中使用模板静态成员函数.代码编译,但不能正常工作(打印出一些垃圾).我想我正在使用正确的语法.我已经读过这个或者这个和其他一些东西,但仍然不知道我做错了什么.代码如下:
#include <iostream>
using namespace std;
class Util {
public:
Util();
virtual ~Util();
template <typename T> static void printTab(T tab[]);
};
template <typename T>
void Util::printTab(T tab[]) {
for (unsigned int i=0; i<sizeof(tab)/sizeof(tab[0]); i++) {
cout << tab[0] << " ";
}
cout << endl;
}
int main() {
float tabFloat[5] {1, 2, 3, 4, 5};
unsigned char tabChar[3] {1, 2, 3};
Util::printTab(tabFloat);
Util::printTab(tabChar);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
任何提示赞赏.
我正在尝试在Windows Server 2003上安装Redmine 2.1.4.为了工作,我需要安装activerecord-mysql-adaptergem,而这似乎依赖于它mysql-2.9.0.gem.我从rubygems下载后者并执行:
gem install mysql-2.9.0.gem
Run Code Online (Sandbox Code Playgroud)
它给出了以下输出:
C:\>gem install mysql-2.9.0.gem
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql-2.9.0.gem:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration …Run Code Online (Sandbox Code Playgroud) 我是Web编程的新手,我正在尝试编写一个简单的应用程序来从输入表单中收集数据并将其传递给servlet HTTPServletRequest.我知道每个servlet都需要映射到里面的特定URL web.xml.我web.xml看起来如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>InputFormTest</display-name>
<welcome-file-list>
<welcome-file>InputForm.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>InputFormTest</display-name>
<servlet-name>InputFormTest</servlet-name>
<servlet-class>com.jsp.core.InputFormTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InputFormTest</servlet-name>
<url-pattern>/InputFormTest</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
InputForm.jsp正确显示.我使用Eclipse的上下文菜单添加了InputFormTest servlet,即New - > Servlet,它具有以下代码:
package jsp.core;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class InputFormTest
*/
public class InputFormTest extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/ …Run Code Online (Sandbox Code Playgroud) 我只是在学习C++中的模板编程,并且链接器无法找到我的class'es构造函数的定义.可能是什么原因?代码如下.
Logger.h
template <class T>
class Logger {
public:
Logger(NodeHandle& nh, char* topic, short pubFrequency);
virtual ~Logger();
void publish();
T& getMsg();
private:
NodeHandle& nh_;
Publisher publisher_;
T msg_;
const char* topic_;
const short pubFrequency_;
};
Run Code Online (Sandbox Code Playgroud)
Logger.cpp
template <class T>
Logger<T>::Logger(NodeHandle& nh, char* topic, short pubFrequency) :
nh_(nh),
topic_(topic),
pubFrequency_(pubFrequency),
publisher_(topic_, static_cast<Msg*>(&msg_)) {}
template <class T>
Logger<T>::~Logger() {}
Run Code Online (Sandbox Code Playgroud)
然后,当我尝试在main.cpp中创建一个Logger实例时
NodeHandle nh;
Logger<std_msgs::String> logger(nh, "test", 10);
Run Code Online (Sandbox Code Playgroud)
链接器抱怨:
undefined reference to `Logger<std_msgs::String>::Logger(NodeHandle&, char*, short)'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?没有编译器错误,所以所有包含都在那里,我猜.
我需要复制构造一个对象,同时将它的类型更改为另一个类,它是同一个类层次结构的成员.我已经阅读过多态复制构造函数,并且(希望)理解它背后的想法.然而,我仍然不知道这种模式是否适用于我的情况,如果适用,如何实施它.我认为最好是在一个例子中展示我需要的东西.
有一Base类和两个子类,Child1和Child2.我需要创建一个Child2基于类型的对象Child1,即.最重要的是,我需要复制的对象p_int指向从Child1到Child2.我写了一个简单的程序来说明它:
#include <iostream>
using namespace std;
class Base {
public:
Base() { p_int = new int; *p_int = 0; }
~Base() { delete p_int; }
virtual Base* clone() const = 0;
void setpInt(int val) { *p_int = val; }
void setInt(int val) { a = val; }
virtual void print() {
cout << "Base: ";
cout << (long)p_int << ":" << *p_int << …Run Code Online (Sandbox Code Playgroud)