相关疑难解决方法(0)

Java如何读取和写入内部属性文件?

我有一个文件,我用来保存我的程序执行时需要的系统信息.程序将从中读取并定期写入.我该怎么做呢?在其他问题中,我遇到路径问题

在此输入图像描述

如果将应用程序部署为runnable jar,我该如何读/写这个属性文件

java properties

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

bouncycastle错误"JCE无法验证提供程序BC"与"jar-with-dependencies"

我正在创建一个使用bouncycastlejava独立应用程序.一切都在日蚀中起作用.我正在创建一个像这样依赖jar.

当我使用"java -jar myapp-0.0.1-SNAPSHOT-jar-with-dependencies.jar"运行应用程序时.

我收到以下错误:

java.io.IOException: exception encrypting data - java.lang.SecurityException: JCE cannot authenticate the provider BC
Run Code Online (Sandbox Code Playgroud)

我的代码:

    Security.addProvider(new BouncyCastleProvider());        
    String keystoreDirectory = "C:/myapp/security";
    File file = new File(keystoreDirectory + "/" + PRIVATE_KEY_FILE);

    if (!file.isFile()) {
        try {

            Configuration idOrganization = configurationBoundary.find(Configuration.ID_ORGANIZATION);

            KeyStore store = KeyStore.getInstance("PKCS12", SECURITY_PROVIDER);
            char[] password = KEY.toCharArray();

            store.load(null, password);

            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", SECURITY_PROVIDER);
            keyPairGenerator.initialize(2048);
            KeyPair pair = keyPairGenerator.generateKeyPair();

            X500Name issuer = new X500Name("CN=" …
Run Code Online (Sandbox Code Playgroud)

java bouncycastle executable-jar

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

Maven 构建带有依赖项的 jar

我正在使用 Maven Swing 应用程序,但在构建时遇到了一些问题。

环境

我正在使用 Netbeans 8.2 作为我的 IDE 和 Jasper Reports 库来开发我的应用程序,以根据编译.jasper文件生成一些 PDF 报告,这些文件是使用 Jaspersoft Studio 6.3.1 单独生成的,然后在我的项目中用作资源。

我的项目的pom如下(具有相关信息的专家):

<project>
    <!-- Needed for jasperreports-functions -->
    <repositories>
        <repository>
            <id>jr-ce-releases</id>
            <url>http://jaspersoft.artifactoryonline.com/jaspersoft/jr-ce-releases</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.4.0</version>
        </dependency>

        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-functions</artifactId>
            <version>5.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.12</version>
        </dependency>

        <!-- The driver I need for connecting to my DB -->
        <dependency>
            <groupId>com.ibm.informix</groupId>
            <artifactId>jdbc</artifactId>
            <version>4.10.8.1</version>
        </dependency>

        <!-- some other test dependencies -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version> …
Run Code Online (Sandbox Code Playgroud)

java dependency-management maven

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

如何使用 IntelliJ 制作具有所有依赖项的 jar 文件,即 Fat jar

我正在尝试制作包含项目中所有依赖项的 jar 文件。我正在使用 IntelliJ。

我尝试了两种方法。

  1. 在 IntelliJ 右上角的 Maven 窗口中,我单击了下面的 pom.xml 中的“clean”和“package”。
    但它不包含任何依赖项。
    我在 window 中使用 IntelliJ,所以我无法点击下面的 CLI 链接。我正在使用 IntelliJ 右上部分的 GUI maven 窗口。
    如何使用 Maven 创建具有依赖项的可执行 JAR?

  2. 我单击了下面的链接中的“构建-构建工件 - 构建”。 如何正确从 IntelliJ 构建 jar? 它似乎包含其他库,但由于某种原因我无法执行该文件。所以,请让我使用 maven window,而不是 build-artifact。

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>secret.App</groupId>
  <artifactId>mt</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>mt</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java jar intellij-idea maven-plugin maven

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

如何将pom项目打包为runnable jar

我有一个基于免费和开源程序的免费项目:

  • 其中一些有pom和公共可访问的罐子
  • 他们中的一些人有pom但没有公共无障碍罐子
  • 他们中的一些没有pom

我想将项目作为一个独特的jar分发,因为我合法地可以兼容所有许可证,如果有可能用maven生成这样的jar,我不知道如何.你能帮我吗?

如果不可能分发此类项目的最佳方式是什么?


我的pom由netbeans管理,这是缺少的配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <!-- I added the following -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>net.hypermove.graphitidb.GraphitiDB</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

java jar maven

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

IntelliJ Maven硒构建罐

我正在使用IntelliJ 12,Java 7,Selenium 2.31.0和Maven。我可以在IDE之外运行测试,但尝试创建jar文件时遇到问题。我可以创建jar文件,双击mvn clean,然后双击安装。一切都很好,罐子就创建了。当我通过命令行运行jar时,会发生问题。

java -jar xyz-selenium-test-1.0.jar

返回:线程“主”中的异常java.lang.NoClassDefFoundError:org / openqa / selenium / WebDriver

我在项目设置中将selenium-server-standalone-2.31.0.jar添加为库,并在项目设置中将其添加为依赖模块。我必须在pom文件中丢失某些内容,但我只是不知道它是什么。我还附加了我的pom文件。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz.selenium.test</groupId>
<artifactId>xyz-selenium-test</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>xyz-selenium-test</name>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>selenium-jar</groupId>
<artifactId>selenium-server-standalone-2.31.0.jar</artifactId>
<version>2.31.0</version>
<scope>system</scope>
<systemPath>/usr/local/selenium/selenium-server-standalone-2.31.0.jar</systemPath>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.0</version> …
Run Code Online (Sandbox Code Playgroud)

java selenium jar intellij-idea maven

0
推荐指数
1
解决办法
2073
查看次数

Maven 运行 mvn 包时找不到目标“单一”

我正在尝试用 maven 编译一些 java 类来生成一个独立的可执行 jar 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>grids</groupId>
<artifactId>grids</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MainMap_Challange</name>
<description>Tickets and Events System</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id> <!-- this is used for inheritance merges -->
          <phase>package</phase> <!-- bind to the packaging phase -->
          <goals>
            <goal>single</goal>
          </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

我想生成一个独立的 jar 文件,就像这里解释的 https://maven.apache.org/plugins/maven-assembly-plugin/usage.html

我得到的错误是:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MainMap_Challange 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD …
Run Code Online (Sandbox Code Playgroud)

java maven

0
推荐指数
1
解决办法
4061
查看次数

如何制作可运行的jar文件?

我曾经使用过一个程序来制作可运行的 .jar 文件。我现在找到的所有文件都是制作 .exe 文件的。我记得它还可以选择将文件制作为 .sh 脚本。有人知道它的名字吗?我已经搜索了几个小时但无济于事:/

java jar

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

如何在生成的 jar 文件的清单中指定主类?

我尝试使用 Eclipse Maven 构建具有依赖项的 jar,但是当我执行时

java -jar App.jar
Run Code Online (Sandbox Code Playgroud)

得到错误:“没有找到主要方法”

我的 pom.xml 看起来像这样:

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.maventest</groupId>
    <artifactId>aproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>aproject</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

它只是一个简单的java代码:

package com.maventest.aproject;

public class App {
    public static void main( String[] args ) {
        System.out.println( "Hello World!" );
    }
}
Run Code Online (Sandbox Code Playgroud)

日食版本:4.5.2

谁能帮我这个?谢谢。

java maven

-1
推荐指数
1
解决办法
9940
查看次数