小编nat*_*j07的帖子

为什么我的Java应用程序找不到我的属性文件

我有一个简单的应用程序,可以读取和写入属性文件.它是在NetBeans中开发的,当从Netbeans内部运行时工作得很好.但是,现在我已经构建并部署了无法找到的属性文件.

项目结构

com/company/projectname/controller/controllerclass.java <- this is where the code using the properties file exists

conf/runController.properties <- the properties file, this exists here
Run Code Online (Sandbox Code Playgroud)

在代码中我有以下访问属性文件:

private final String PROPERTIESFILELOCATION = "conf/runController.properties";

public void runController(){
this.runController = new Properties();
this.propertiesLocation = this.getClass().getClassLoader().getResource(this.PROPERTIESFILELOCATION);
FileInputStream propsInput = new FileInputStream(this.propertiesLocation.getFile());
this.runController.load(propsInput);
}
Run Code Online (Sandbox Code Playgroud)

(为简洁起见)

当我从命令行调用jar文件时,我发出:

java -classpath /usr/java/projectdirectory/project.jar com.company.projectname.controller.controllerclass arg1
Run Code Online (Sandbox Code Playgroud)

所以,我已经成功地在其他项目上实现了这一点,但由于某种原因,这是行不通的.

我已经检查了jar文件中的结构,并且所有内容都符合预期.

任何人都可以指出我的错误,并帮我启动并运行吗?

编辑 - 更改名称以匹配.它们在我的代码中始终保持一致

java jar properties

7
推荐指数
1
解决办法
1万
查看次数

Golang - pgbouncer 和事务使用

技术细节

  • 去版本1.2
  • 用于 go bmizerany/pq 的 postrgres 库

这个问题让我发疯,我希望有人能够提供帮助。

我在 golang 中开发了一个应用程序,用于从 postgres 数据库读取数据,并对每条记录发出 http 请求,然后更新数据库。

这一切都很简单。不过,我们有 pgbouncer。我们对 pgbouncer 的配置是不支持准备好的语句。Go 默默地将所有查询包装在准备好的语句中。pgbouncer 解决这个问题的方法是设置一个事务。对于插入/更新/删除之类的事情来说,这一切都很好。

对于 select 语句,我将其包装在事务中:

func TransactionQuery(db *sql.DB, baseQuery string) (rows *sql.Rows, code int, err error) {
        tx, txErr := db.Begin()
        if txErr != nil {
            return nil, -1, txErr
        }

        selectStmt, prepErr := tx.Prepare(baseQuery)
        if prepErr != nil {
            return nil, -1, fmt.Errorf("Failed to prepare statment: %s Error: %v", baseQuery, prepErr)
        }

        defer func() {
            if stmtErr := selectStmt.Close(); …
Run Code Online (Sandbox Code Playgroud)

postgresql go pgbouncer

5
推荐指数
1
解决办法
3049
查看次数

HTTP GET检索压缩文件

我已经开发了一个HTTP通信对象,用于通过GET请求下载文件.

这在下载文本文件时工作得很好.但是,下载压缩文件(如zip,gz或tar.gz)似乎会下载该文件,但该文件无效.

在zip的情况下,我得到一个meesage说它试图在文件的开始之前移动指针.在.tar.gz的情况下,消息是file.tar中的数据错误.文件坏了.

在所有情况下,我使用的下载链接都允许从URL进行完整和正确的下载.然而,基于Java代码的下载使文件失效但无效.

代码如下:

public class HTTPCommunicationGet {

    private URIBuilder sendData;
    private URI target;
    private HttpGet getConnection;

    public HTTPCommunicationGet(String url, TreeMap<String, String> components) {
        super(url, components);
    }

    public HTTPCommunicationGet(String url, String queryString) {
        super(url, queryString);
    }

    protected void defineSendData() throws URISyntaxException, IOException {
        this.sendData = new URIBuilder(new URI(this.getUrl()));
        if (this.getComponents() != null && this.getComponents().size() > 0) {
            for (Map.Entry<String, String> component : this.getComponents().entrySet()) {
                this.sendData.setParameter(component.getKey(), component.getValue());
            }
        }
    }

    protected void retrieveRemoteData() throws IOException, MalformedURLException, URISyntaxException, DataMapHTTPGetException {

        this.target …
Run Code Online (Sandbox Code Playgroud)

java zip gzip http

2
推荐指数
1
解决办法
1940
查看次数

标签 统计

java ×2

go ×1

gzip ×1

http ×1

jar ×1

pgbouncer ×1

postgresql ×1

properties ×1

zip ×1