[英]Exporting and running Intellij .jar projects
I have exported a Java project using Intellij following the steps in this question and got a .jar file in %PROJECT_ROOT%/out/artifacts/ContactRetriever.jar
. 我已按照此问题中的步骤使用Intellij导出了Java项目,并在
%PROJECT_ROOT%/out/artifacts/ContactRetriever.jar
获得了一个.jar文件。 However, when running the .jar file from the command line, 但是,从命令行运行.jar文件时,
java -jar ContactRetriever.jar
the following output is given: 给出以下输出:
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)
The manifest file ( MANIFEST.MF
) of my project contains: 我的项目的清单文件(
MANIFEST.MF
)包含:
Manifest-Version: 1.0
Main-Class: Main
Main
is the main class (entry point). Main
是主类(入口点)。
The layout of the project is: 该项目的布局为:
The project structure artifacts are: 项目结构工件为:
and the modules: 和模块:
Why isn't main being executed? 为什么不执行main?
Edit: 编辑:
The code in main is: 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);
}
}
Just like the error said, you have a duplicate dependency: org.seleniumhq.selenium/selenium-java Remove one of the dependencies and your app must run fine. 就像错误所说的一样,您有一个重复的依赖项:org.seleniumhq.selenium / selenium-java删除其中一个依赖项,您的应用程序必须运行良好。
Then add the configuration for maven to create the manifest file: 然后添加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>
I've also met this problem, and i found that Intellij will automatically generate META-INF/MANIFEST.IF
under src/main/java
, but it should be under src/main/java/resources
, just move it to the correct directory. 我也遇到了这个问题,我发现Intellij会在
src/main/java
下自动生成META-INF/MANIFEST.IF
,但它应该在src/main/java/resources
,只需将其移至正确的目录即可。 it worked for me. 它为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.