在过去的几个小时里,我一直试图解决这个问题而且我无处可去.我刚刚安装了Maven for Eclipse插件(M2E,我认为)以及maven,mvn.我创建了一个非常简单的Hello World项目,并尝试使用以下命令运行构建的jar:java -jar pimidi-0.0.1-SNAPSHOT.jar
无论我尝试什么,我总是得到相同的错误:没有主要的清单属性,在目标/ pimidi-0.0.1-SNAPSHOT.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.dan</groupId>
<artifactId>pimidi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>pimidi</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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.dan.pimidi.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我已经在POM的清单节点(类路径,清单位置),不同的插件(汇编,编译等)中尝试了无数不同的选项,但无济于事.在查看Eclipse中的有效POM时,我可以看到maven-jar-plugin已经包含在更高级别的POM中,对项目POM的任何更改都被省略.
有没有人对如何使这个工作有任何想法?如果这个问题缺乏细节,我会道歉 - 我今晚的精神力已经过期了.任何帮助将不胜感激!
我已尝试使用以下代码在本地系统上连接CASSANDRA数据库.
这是我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConnect {
public static void main(String[] args) throws Exception{
Connection con = null;
try {
Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/mykeyspace");
String query = "select * from users";
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(query);
while (result.next()) {
System.out.println(result.getString("user_id"));
System.out.println(result.getString("fname"));
System.out.println(result.getString("lname"));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (con != null) {
try {
con.close();
} catch …Run Code Online (Sandbox Code Playgroud) 我仍然是java的新手,直到现在我还没有用过的一件事就是调用一个类中的方法,这个类不属于特定项目的一部分.我有两个罐子:ai.jar和functions.jar.在functions.jar里面我里面有很多类,所以它们不在文件夹或任何东西中.在ai.jar中,我有一个访问ai.jar中特定方法的类.我试图通过使用functions.jar/get.class和其他类似的东西创建一个引用变量,但我总是得到一个classnotfoundexception.我该怎么做呢?谢谢!
在尝试从疯狂复杂的ant构建迁移到gradle的持续传奇中 - 我正在生成一些用于'javahelp'的资源jar文件.它们不包含任何类.我需要将创建这些资源jar的项目的输出添加到我的战争的根源(而不是WEB-INF/lib).
我试图解决的问题
apply plugin: 'war'
//Move files into position for the mmplEar project
task stage(overwrite: true, dependsOn: war) << {
}
war {
from project(':help:schedwincli').buildDir.absolutePath + '/libs'
include '*.jar'
}
dependencies {
//Ensure the jar is generated, but we don't want it in the lib dir
providedCompile project(':help:schedwincli')
}
Run Code Online (Sandbox Code Playgroud)
这会编译并运行,并且:help:schedwincli会运行并生成所需的jar,但是当我打开我的war文件时,预期的jar不会出现在战争的任何地方.建议?
编辑
我在下面提出了Peter建议的更改,但现在我收到此错误:
无法在配置容器上找到属性"资源".
这就是它说失败的地方:
from '../../runtime', /*Fails on this line*/
'../../runtime/html',
'../../runtime/html/Jboss',
'../../runtime/props',
'../../runtime/props/Jboss',
'../../scripts',
'../../../proj/runtime',
'../../../proj/runtime/html',
'../../../proj/runtime/html/Jboss',
'../../../proj/runtime/props',
'../../../proj/runtime/props/Jboss',
configurations.resources
include …Run Code Online (Sandbox Code Playgroud) 我需要在maven构建过程中为特定接口创建一个子类列表,然后在运行时使用它来加载这些类.我在我的webapp pom中添加了reflection-maven(来自谷歌代码反射),但在maven构建期间,它只包括来自Web应用程序的类,而不包括该应用程序web-inf/lib文件夹中的打包jar中的类.以下是我使用的直接配置.我查看了插件源代码,它似乎扫描了以下内容:getProject().getBuild().getOutputDirectory().
反正我是否可以配置插件来扫描项目的相关jar文件?
<plugin>
<groupId>org.reflections</groupId>
<artifactId>reflections-maven</artifactId>
<version>0.9.9-RC1</version>
<executions>
<execution>
<goals>
<goal>reflections</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用java类中的Runtime.exec函数从另一个jar运行可执行jar .
代码是
Runtime r = Runtime.getRuntime();
Process p = r.exec("java -jar \""+_JarPath +"\" " + "\""+ args[0]+"\""+ " " +"\""+ args[1]+"\""+ " " +"\""+ args[2]+"\"" + " " +"\""+ args[3]+"\"");
Run Code Online (Sandbox Code Playgroud)
这里,参数args不是null并且定义良好.
此代码在Windows平台上运行良好,但在Linux上,我收到错误
无法访问jarfile"/opt/mydir/lib/MyFol/mytest.jar"
我已经阅读了其他类似的问题并确保了这一点
/opt/mydir/lib/MyFol/和文件mytest.jar具有所有权限我在Linux上使用OpenJDK.
我有一个基于免费和开源程序的免费项目:
我想将项目作为一个独特的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) 当我创建一个JAR时,JAR将不会读取其中的文件夹,只有JAR所在的文件夹中的文件夹.好的,那不是很具描述性.所以这是我编辑支持的照片.
我希望你现在明白这个想法.那么我该如何解决这个问题呢?我已经在eclipse中拥有了res和stats构建路径的一部分,现在是什么?
我用来读取资源的代码:
Image player;
player = new ImageIcon("res/player.png").getImage();
我试图从磁盘的特定位置使用DLL(因为我使用的是JNotify库).
使用Netbeans 7.4,发生了以下情况:
我的临时计划只做:
System.out.println(System.getProperty("java.library.path"));
作为Netbeans中的VM选项,我设置了:-Djava.library.path=D:/JNotify-dll/.计划产出:D:/Jnotify-dll/.
当我正常运行时java <jarfile>:它没有设置主类,而我在Netbeans选项中设置它.
当我运行它时java -jar <jarfile>:它给了我%PATH%变量.
当我运行它作为java -jar <jarfile> -Djava.library.path=D:/JNotify-dll/它仍然给了我,我的%PATH%变量.
有没有人知道发生了什么?我真的厌倦了它.
在MANIFEST.MF通过Netbeans的生成:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.1
Created-By: 1.7.0_25-b17 (Oracle Corporation)
Class-Path: lib/ORM.jar lib/mysql-connector-java-5.1.23-bin.jar lib/co
mmons-dbcp-1.4-javadoc.jar lib/commons-dbcp-1.4.jar lib/commons-pool-
1.6-javadoc.jar lib/commons-pool-1.6.jar lib/jnotify-0.94.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: bf4.bf4logreader.BF4LogReader
Run Code Online (Sandbox Code Playgroud)
编辑: java -jar -Djava.library.path=D:/JNotify-dll/ <jarfile>,但我仍然欣赏答案.
我正在尝试在shell脚本中运行jar文件。我想分配该jar文件的输出并回显它。我尝试了以下类似的方法。
#!/bin/bash
$the_output = "$(java -jar portalOutputFormater.jar $1 $2 $3 $4 2>&1 )"
echo the_output
Run Code Online (Sandbox Code Playgroud)
我的Java程序针对四个输入参数将输出作为“ output = var1_var2_var3_var4”返回。但是我得到的输出是..
portaloutputformatter.sh: line 3: =output=var1_var2_var3_var4: command not found
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?我只需要运行我的jar文件,然后将其分配给变量并输出变量。
谢谢 !