我看到了maven-dependency-plugin这个; 但是,它似乎将所有内容(包括测试jar)复制到目标目录.任何人都知道如何配置此插件以排除测试罐?
几个星期以来,我一直在与maven搏斗,让它"正确"部署我们的项目.
我差不多完成但是我有一个顽固的小问题:
当我使用带有"目录"目标的maven程序集插件时
mvn assembly:directory
我得到了很多控制台输出,如下所示:
[INFO] tomcat/conf already added, skipping
[INFO] tomcat/conf/Catalina already added, skipping
[INFO] tomcat/conf/Catalina/localhost already added, skipping
[INFO] tomcat/webapps already added, skipping
我编写了自己的汇编描述符,它基本上将多个FileSets复制到我们的deploy目录中的各个子目录中.只要将一个FileSet中的文件复制到另一个FileSet已经创建了基本目录结构的位置(以及一些可以覆盖的"默认"文件),就会出现上述消息.
所以,我很难搞清楚:
我如何1)抑制这些消息(但只有"已经添加"消息)或2)允许覆盖?
我从互联网上下载了一个源代码,我正在尝试用maven构建它.这是源代码附带的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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>myArtifact</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myArtifact</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>myArtifact.Main</mainClass>
</manifest>
</archive>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-701.jdbc4</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
mvn install命令正在生成jar文件,但我无法执行此文件,因为缺少依赖项(在此示例中未找到与postgresql依赖项相关的类异常).
我注意到maven已正确下载了依赖项(jar库都在本地maven存储库目录中)但是mvn install并没有将这些库复制到生成的jar文件中.我怎样才能做到这一点?
谢谢.
操作系统名称:"linux"版本:"2.6.32-27-generic"arch:"i386"系列:"unix"
Apache Maven 2.2.1(r801777; 2009-08-06 12:16:01-0700)
Java版本:1.6.0_20
我试图在ubuntu中使用maven与maven相关联.如果我移动maven下载到我的$ JAVA_HOME/jre/lib/ext /文件夹中的"mysql-connector-java-5.1.14.jar"文件,那么当我运行jar时一切都很好.
我想我应该只能在pom.xml文件中指定依赖项,maven应该自动设置依赖项jar的类路径.这是不正确的?
我的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.ion.common</groupId>
<artifactId>TestPreparation</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestPrep</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.ion.common.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JUnit testing dependency -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.14</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
命令"mvn package"构建它没有任何问题,我可以运行它,但是当应用程序尝试访问数据库时,会出现以下错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at …Run Code Online (Sandbox Code Playgroud) 在构建了一个示例mvn项目之后,我添加了我的org.restlet依赖项和Java代码.
然后,我成功构建了我的JAR mvn install.最后,我在尝试运行JAR时遇到了错误.
vagrant$ java -jar target/my-app-1.0-SNAPSHOT.jar
Failed to load Main-Class manifest attribute from
target/my-app-1.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud) 我想将它打包在一个可执行的jar中以便分发.我需要一个像main.jar这样的可执行文件,并且所有依赖项都在libs/*.jar中
如何在没有预先包含到依赖库的情况下制作maven可执行jar?
在如何使用Maven创建具有依赖关系的可执行JAR?2010年12月1日10:46安德烈·阿隆森回答了一个注释,但是那个根本不起作用(失败的sadescriptorRef未设置).
我是maven的初学者,不懂很多东西.我可以构建简单的可执行jar,但是如何将multimodule maven项目构建到可执行jar中对我来说是不可思议的.所以,我有三个项目.家长:
<?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>org.example</groupId>
<artifactId>Test</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>Main</module>
<module>Dep</module>
</modules>
</project>
Run Code Online (Sandbox Code Playgroud)
还有两个子项目:
<?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">
<parent>
<artifactId>Test</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Main</artifactId>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>Dep</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
和:
<?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">
<parent>
<artifactId>Test</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Dep</artifactId>
</project>
Run Code Online (Sandbox Code Playgroud)
主模块有Main类和main方法(lol)
public class Main {
public static void main(String[] args) {
Hello hello = new Hello();
System.out.println(hello.sayHello());
}
} …Run Code Online (Sandbox Code Playgroud) 是否有可能实际构建一个包含java代码的maven项目,并且可以共享二进制文件?
问题:我正在尝试构建的项目需要大约3-4个小时,并且需要高互联网带宽.我试图检查在其他几台机器中重新使用这个构建项目的可能性.
我之前使用过涉及makefile的c ++项目,这非常简单.我是Java/eclipse的新手,需要帮助才能弄清楚这是否真的有可能.
PS:我确实试图找到现有的解决方案; 他们不是明星前锋,或者他们说不能这样做
我能够使用Maven编译并启动我的Spring项目:
mvn -e clean compile exec:java -Dexec.mainClass=de.fraunhofer.fkie.tet.vmware.manager.Test
Run Code Online (Sandbox Code Playgroud)
但是,当我使用maven-assembly-plugin(包括applicationContext.xml)在一个文件中组装所有jar时,我总是Exception在java执行期间得到一个:
java -cp target/test-jar-with-dependencies.jar:. de.fraunhofer.fkie.tet.vmware.manager.Test
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Sep 6, 2010 10:37:21 AM org.springframework.util.xml.SimpleSaxErrorHandler warning
WARNING: Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
...
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: …Run Code Online (Sandbox Code Playgroud) 首先,这是一个非常n00b的问题.但作为一名初级开发人员,我从未需要导入和使用其他Java框架.标准库总是足以让我编写我需要编写的类.
但现在接触到更多"高级"概念,我需要开始使用外部框架,例如JSON for Java,Apache的HttpClient for java等等.我正在寻找一个基本的理解如何工作以及如何导入这些库,以便您可以开始使用这些类...
所以我最初的理解是每个fraemworks都会为你提供一个包含框架所有类的.jar文件.然后将其导入到您的项目中,看看您只需导入项目中的类/库,例如'import org.json.*;'
理解是否正确?