簡體   English   中英

導出和運行Intellij .jar項目

[英]Exporting and running Intellij .jar projects

我已按照問題中的步驟使用Intellij導出了Java項目,並在%PROJECT_ROOT%/out/artifacts/ContactRetriever.jar獲得了一個.jar文件。 但是,從命令行運行.jar文件時,

java -jar ContactRetriever.jar

給出以下輸出:

    Xalan-J command line Process class options:

                            -Common Options-

       [-XSLTC (use XSLTC for transformation)]
       [-IN inputXMLURL]
       [-XSL XSLTransformationURL]
       [-OUT outputFileName]
       [-E (Do not expand entity refs)]
       [-EDUMP {optional filename} (Do stackdump on error.)]
       [-XML (Use XML formatter and add XML header.)]
       [-TEXT (Use simple Text formatter.)]
       [-HTML (Use HTML formatter.)]
       [-PARAM name expression (Set a stylesheet parameter)]
       [-MEDIA mediaType (use media attribute to find stylesheet associated with a d
    ocument.)]
       [-FLAVOR flavorName (Explicitly use s2s=SAX or d2d=DOM to do transform.)]
       [-DIAG (Print overall milliseconds transform took.)]
       [-URIRESOLVER full class name (URIResolver to be used to resolve URIs)]
       [-ENTITYRESOLVER full class name (EntityResolver to be used to resolve entiti
    es)]

(press <return> to continue)

我的項目的清單文件( MANIFEST.MF )包含:

Manifest-Version: 1.0
Main-Class: Main

Main是主類(入口點)。

該項目的布局為:

布局

項目結構工件為:

文物

和模塊:

模組

為什么不執行main?

編輯:

main中的代碼是:

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.util.Cookie;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Level;


public class Main  extends Defaults{

    private static WebClient webClient;

    public static void main(String[] args) {
        if(args.length == 0) {
            printUsage();
            return;
        }

        if(args[1] == null)
            initAccounts("");
        else
            initAccounts(args[2]);

        if(args[4] == null || args[6] == null)
            printUsage();
        else
            getContacts(args[4], args[6], 4);

            // initAccounts("");
            // getContacts("C:\\Users\\user\\Downloads", "C:\\Users\\user\\Projects\\ContactRetriever", 4);
    }
}

就像錯誤所說的一樣,您有一個重復的依賴項:org.seleniumhq.selenium / selenium-java刪除其中一個依賴項,您的應用程序必須運行良好。

然后添加maven的配置以創建清單文件:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${java.specification.version}</source>
                <target>${java.specification.version}</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>Main</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.9</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib/</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我也遇到了這個問題,我發現Intellij會在src/main/java下自動生成META-INF/MANIFEST.IF ,但它應該在src/main/java/resources ,只需將其移至正確的目錄即可。 它為我工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM