我有一個從maven項目構建的jar文件。在這裏,我有春季靴子和碼頭。我的項目的目的是在我的網站上實現網絡套接字。 Jetty的Web套接字實現不包含主要方法,只有一個類,因此它知道在獲取Web套接字請求時該怎麼做。然後我嘗試了java -jar target/myproject-0.0.1-SNAPSHOT.jar,但是我得到了錯誤'沒有主清單屬性。「我不確定爲什麼我需要一個。任何建議將不勝感激。 我的POM文件:如何在沒有主清單屬性的情況下執行jar?
<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>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myName</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>repo2_maven_org</id>
<url>http://repo2.maven.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.1.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.0.v20150612</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.3.0.v20150612</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.3.0.v20150612</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.0.v20150612</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我唯一的Java代碼:
import java.io.IOException;
import java.util.ArrayList;
import javax.websocket.CloseReason;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/jsr356toUpper")
public class ToUpper356Socket {
private ArrayList<Session> sessions = new ArrayList<Session>();
@OnOpen
public void onOpen(Session session) {
sessions.add(session);
System.out.println("WebSocket opened: " + session.getId());
}
@OnMessage
public void onMessage(String txt, Session session) throws IOException {
System.out.println("Message received: " + txt);
for (Session ses : sessions){
ses.getBasicRemote().sendText(txt);
}
}
@OnClose
public void onClose(CloseReason reason, Session session) {
sessions.remove(session);
System.out.println("Closing a WebSocket due to " + reason.getReasonPhrase());
}
}
當你執行'MVN包'(或者「之後的任何其他目標」,比如'mvn instal l'),Maven生成一個清單文件。很難說有什麼可能是關於你的項目的細節的問題。請添加您的pom文件,以便我們看到配置。 –
添加了pom! :D –