标签: executable-jar

可执行JAR中的eclipselink PersistenceUnitLoadingEception

我正在开发一个使用eclipselink的独立java应用程序.从eclipse IDE执行应用程序时,一切都很好.但是我已经导出了一个可执行的JAR文件,因为我无法使eclipseLink工作.我也发现了类似的问题在Eclipse社区论坛在这里,但还没有太顺手:

请帮忙,

我的例外情况如下:

01 dec. 2010 22:47:31,199  INFO Configuration:97 - Iniciate database
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.2.v
20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExcept
ion
Exception Description: An exception was thrown while searching for persistence a
rchives with ClassLoader: java.net.URLClassLoader@61de33
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services
- 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoad
ingExceptionException Description: An exception was thrown while processing …

persistence jpa executable-jar classloader eclipselink

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

从同一文件夹中的JAR访问文件

我需要从JAR文件(可执行jar)访问(创建和读取)文件,并且该文件应该在与JAR相同的目录中创建

我尝试过, this.getClass().getResource("myFile") 但由于jar中有包,它不起作用..

我也试着写 File f = new File("myFile"); f.createNewFile();

如果我从终端执行JAR,那么这是有效的,但如果我通过双击它来执行JAR,那么该文件将在我的主目录中创建 - .-''

我如何访问一个文件,确保该文件作为JAR文件在SAME目录中?

(当然也获得jar绝对路径会起作用,因为我可以从中获取父文件夹)

java directory jar file executable-jar

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

Java - 在JAR文件中写入txt

可能重复:
Java程序如何使用.jar中的文件进行读写?

如何从JAR java编译的项目中写入.txt文件?

当我运行我的项目时,它不会给出错误,但它不会写入JAR文件中的.txt.

我使用以下方法制作JAR文件:

netbeans clean /build tool
Run Code Online (Sandbox Code Playgroud)

码:

public class FileIO   {
    private File file;
    private Scanner filescScanner, lineScanner;
    private PrintWriter fileWriter;
    private String[][] data;

    public FileIO () {
        data = new String[100][2];
    }

    public String[][] getLineScores(){
        return this.loadHighscores(this.getClass().getResourceAsStream("LineHighscores.txt"));
    }

    public String[][] getTimeScores(){
        return this.loadHighscores(this.getClass().getResourceAsStream("TimeHighscores.txt"));
    }

    public void setLineScores( String name,String lines ){
        boolean found= false;
        data = this.getLineScores();
        for(int i = 0; i<data.length && !found ; i++){
            if(data[i][0] == null || "Niemand".equals(data[i][0])){
                data[i][0]=name;
                data[i][1]=lines;
                found=true; …
Run Code Online (Sandbox Code Playgroud)

java file-io jar executable-jar streamwriter

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

如何从当前运行的jar中复制文件

我有一个.jar,它有两个依赖的.dll文件.我想知道是否有任何方法可以将这些文件从.jar中复制到运行时的用户临时文件夹中.这是我当前的代码(编辑为只有一个.dll加载以减少问题大小):

public String tempDir = System.getProperty("java.io.tmpdir");
public String workingDir = dllInstall.class.getProtectionDomain().getCodeSource().getLocation().getPath();

public boolean installDLL() throws UnsupportedEncodingException {

try {
             String decodedPath = URLDecoder.decode(workingDir, "UTF-8");
             InputStream fileInStream = null;
             OutputStream fileOutStream = null;

             File fileIn = new File(decodedPath + "\\loadAtRuntime.dll");
             File fileOut = new File(tempDir + "loadAtRuntime.dll");

             fileInStream = new FileInputStream(fileIn);
             fileOutStream = new FileOutputStream(fileOut);

             byte[] bufferJNI = new byte[8192000013370000];
             int lengthFileIn;

             while ((lengthFileIn = fileInStream.read(bufferJNI)) > 0) {
                fileOutStream.write(bufferJNI, 0, lengthFileIn);
             }

            //close all steams
        } catch (IOException e) { …
Run Code Online (Sandbox Code Playgroud)

java jar executable-jar

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

从嵌入式Tomcat 7的已编译jar文件加载webapp

我通常使用嵌入式jetty服务器开发Web应用程序,并使用Launcher4j等应用程序将它们包装在.exe文件中.我喜欢将我的Web应用程序文件夹放在java包中并从那里读取它,而不是将它放在生成的.exe文件旁边的文件夹中.我喜欢这样做以保护我的webapp不被编辑.使用嵌入式jetty服务器,它是这样完成的:

String jetty_home = MyClass.class.getClassLoader().getResource(webappsClassPath).toExternalForm();
    WebAppContext webapp = new WebAppContext();
    webapp.setServer(server);
    webapp.setContextPath(contextPath);
    webapp.setResourceBase(jetty_home + "/webapps/MyWebapp");
    webapp.setWar(webappsFolder);
    webapp.setParentLoaderPriority(true);
Run Code Online (Sandbox Code Playgroud)

如何使用嵌入式Tomcat 7或Tomcat 8-alpha服务器进行相同的管理?谢谢!:)

jsp web-applications executable-jar embedded-tomcat-7

5
推荐指数
0
解决办法
548
查看次数

Java的+ Maven的+使可执行的JAR +异常在线程 "主要" java.lang.NoClassDefFoundError:组织/ SLF4J /的LoggerFactory

我有一个执行jar的问题.

当我做:

mvn package 
Run Code Online (Sandbox Code Playgroud)

我在目标文件夹中获取了jar,但是当我想运行它时,我在slf4j api的LoggerFactory上得到一个NoClassDefFoundError.

这是我的POM.xml:

<?xml version="1.0"?>
<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.6</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.1</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>org.t0tec.main.Start</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)

知道配置有什么问题吗?

java jar executable-jar slf4j maven

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

使用可执行Jar时找不到Spring-Boot资源

我再次遇到一个奇怪的问题,希望有人可以提供帮助.

我有一个spring boot后端模块,在Eclipse中启动main时,应用程序是可执行的.一切都很好.

我的应用程序使用ss/main/resources文件夹中包含的csv文件将示例数据导入数据库.如上所述,在eclipse中启动时一切正常.

现在我想将它作为可执行jar执行,应用程序开始启动然后无法启动,因为它无法找到csv文件.它打印出来的路径,它在哪里查找文件,是正确的,并且csv文件包含在jar中.

该模块的Pom如下所示:

<project>
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>at.company.bbsng</groupId>
        <artifactId>bbsng-import</artifactId>
        <version>0.1.0-SNAPSHOT</version>
    </parent>

    <artifactId>bbsng-import-backend</artifactId>
    <name>bbsng-import-backend</name>

    <properties>
        <start-class>at.company.bbsng.dataimport.Application</start-class>
    </properties>


    <dependencies>

        <!-- SPRING ... -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
            <!-- EXCLUDE LOGBACK AND USE LOG4J -->
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-logging</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- COMMONS ... -->

        ...

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

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

csv文件的路径在propery文件中配置如下:

# EXAMPLE PATH
csv.path=config/csv/
Run Code Online (Sandbox Code Playgroud)

java配置文件的部分如下:

  ...

  @Value("${csv.path}")
  private …
Run Code Online (Sandbox Code Playgroud)

java resources filenotfoundexception executable-jar spring-boot

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

为什么在导出Runnable Jar时Eclipse使用旧版本的代码?

当我在Eclipse中运行它时,我有一个项目可以很好地运行。但是,当我将其导出为可运行的Jar时,它从几天前就为我提供了该项目的旧版本。

我不知道为什么或如何导出据我所知不再存在的旧代码和文件。

我尝试执行Project> Clean,但是没有用

这是一个已知的月食错误吗?

有什么建议么?

java eclipse executable-jar eclipse-mars

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

Maven可执行程序Jar在启动时抛出错误

首先:我是maven的新手.我制作了我的第一个maven应用程序并在IDE中成功测试了它.构建总是成功的,一切都像魅力一样.

现在我想将项目导出为内置依赖项的可执行jar,但我不确定它为什么不起作用.

我将以下内容添加到我的pom文件中,因为这是我在类似问题的各种答案中找到的

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.pwc.scfa.pensareautomatio3.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

我知道这指定了JVM启动的主类,因为IDE没有自动设置它.

我将jar放在目标目录中,将其复制到另一个目录并尝试执行它.

遗憾的是,引发了以下错误:

在此输入图像描述

在此输入图像描述

能否请你给我一个提示,我可能出错了?那太好了.(我正在使用NetBeans,如果有任何帮助的话.)

这是我的StackTrace:

C:\Users\scfa\Desktop>java -jar PensareAutomatio-1.1.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/openxm
l4j/exceptions/InvalidFormatException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.openxml4j.exceptions
.InvalidFormatException
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source) …
Run Code Online (Sandbox Code Playgroud)

java netbeans build executable-jar maven

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

无法使用可执行jar文件在Linux服务器上运行Chrome驱动程序

我正在尝试运行可执行的jar文件,该文件将通过使用命令java -jar -webdriver.chrome.driver = pathofchromedriver myjarfile.jar在Linux环境中执行测试套件(使用硒/黄瓜)。

我有以下错误:

在端口29256上启动ChromeDriver 2.41.578700(2f1ed5f9343c13f73144538f15c00b370eda6706)仅允许本地连接。[1534896949.211] [SEVERE]:bind()返回错误,errno = 99:无法分配请求的地址(99)

我试图更改chrome驱动程序版本,但无法正常工作。有人知道如何解决它吗?

linux executable-jar selenium-chromedriver

5
推荐指数
0
解决办法
2104
查看次数