2017-12-26 8 views
0

Maven을 시작하면서 해결할 수없는 문제가 발생했습니다. 내 응용 프로그램을 실행하는 데 필요한 항아리 파일이 클래스 경로에없는 것 같습니다. maven 패키지 중에 Maven이 이것을 돌봐주지 않아야합니까? 내가 MVN 패키지를 실행하면포장 중에 classpath에 jar 파일을 포함하지 않음

, 내가 얻을 오류 :

[ERROR] /home/dev/Desktop/maventest/my-app/src/main/java/com/mycompany/app/App.java:[79,9] cannot find symbol 
    symbol: class UpnpService 
    location: class com.mycompany.app.App 
[ERROR] /home/dev/Desktop/maventest/my-app/src/main/java/com/mycompany/app/App.java:[79,39] cannot find symbol 
    symbol: class UpnpServiceImpl 
    location: class com.mycompany.app.App 

샘플 코드를 말하는가 : "당신은 집착-core.jar를하고 종속성이 필요 - 당신의 클래스 패스 (원활한 * 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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.mycompany.app</groupId> 
    <artifactId>my-app</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>my-app</name> 
    <url>http://maven.apache.org</url> 

    <repositories> 
    <repository> 
     <id>4thline-repo</id> 
     <url>http://4thline.org/m2</url> 
     <snapshots> 
     <enabled>false</enabled> 
     </snapshots> 
    </repository> 
    </repositories> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.fourthline.cling</groupId> 
     <artifactId>cling-core</artifactId> 
     <version>2.1.1</version> 
    </dependency> 
    </dependencies> 
</project> 

그리고 여기 샘플 코드 나 실행하는 것을 시도하고있다 : 정말 http://4thline.org/projects/cling/core/manual/cling-core-manual.xhtml#chapter.GettingStarted

겠습니까 :

package com.mycompany.app; 

import org.fourthline.cling.model.message.header.STAllHeader; 
import org.fourthline.cling.model.meta.LocalDevice; 
import org.fourthline.cling.model.meta.RemoteDevice; 
import org.fourthline.cling.registry.Registry; 
import org.fourthline.cling.registry.RegistryListener; 

/** 
* Runs a simple UPnP discovery procedure. 
*/ 
public class App { 

    public static void main(String[] args) throws Exception { 

     // UPnP discovery is asynchronous, we need a callback 
     RegistryListener listener = new RegistryListener() { 

      public void remoteDeviceDiscoveryStarted(Registry registry, 
                RemoteDevice device) { 
       System.out.println(
         "Discovery started: " + device.getDisplayString() 
       ); 
      } 

      public void remoteDeviceDiscoveryFailed(Registry registry, 
                RemoteDevice device, 
                Exception ex) { 
       System.out.println(
         "Discovery failed: " + device.getDisplayString() + " => " + ex 
       ); 
      } 

      public void remoteDeviceAdded(Registry registry, RemoteDevice device) { 
       System.out.println(
         "Remote device available: " + device.getDisplayString() 
       ); 
      } 

      public void remoteDeviceUpdated(Registry registry, RemoteDevice device) { 
       System.out.println(
         "Remote device updated: " + device.getDisplayString() 
       ); 
      } 

      public void remoteDeviceRemoved(Registry registry, RemoteDevice device) { 
       System.out.println(
         "Remote device removed: " + device.getDisplayString() 
       ); 
      } 

      public void localDeviceAdded(Registry registry, LocalDevice device) { 
       System.out.println(
         "Local device added: " + device.getDisplayString() 
       ); 
      } 

      public void localDeviceRemoved(Registry registry, LocalDevice device) { 
       System.out.println(
         "Local device removed: " + device.getDisplayString() 
       ); 
      } 

      public void beforeShutdown(Registry registry) { 
       System.out.println(
         "Before shutdown, the registry has devices: " 
         + registry.getDevices().size() 
       ); 
      } 

      public void afterShutdown() { 
       System.out.println("Shutdown of registry complete!"); 

      } 
     }; 

     // This will create necessary network resources for UPnP right away 
     System.out.println("Starting Cling..."); 
     UpnpService upnpService = new UpnpServiceImpl(listener); 

     // Send a search message to all devices and services, they should respond soon 
     upnpService.getControlPoint().search(new STAllHeader()); 

     // Let's wait 10 seconds for them to respond 
     System.out.println("Waiting 10 seconds before shutting down..."); 
     Thread.sleep(10000); 

     // Release all resources and advertise BYEBYE to other UPnP devices 
     System.out.println("Stopping Cling..."); 
     upnpService.shutdown(); 
    } 
} 

예제 코드에서이다 당신의 도움을 주셔서 감사합니다.

답변

0

Maven은 당신이 당신의 pom.xml 파일을 교체의 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.app</groupId> 
    <artifactId>my-app</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>my-app</name> 
    <url>http://maven.apache.org</url> 

    <repositories> 
    <repository> 
     <id>4thline-repo</id> 
     <url>http://4thline.org/m2</url> 
     <snapshots> 
     <enabled>false</enabled> 
     </snapshots> 
    </repository> 
    </repositories> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.fourthline.cling</groupId> 
     <artifactId>cling-core</artifactId> 
     <version>2.1.1</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.fourthline.cling/cling-core --> 
    <dependency> 
     <groupId>org.fourthline.cling</groupId> 
     <artifactId>cling-core</artifactId> 
     <version>2.1.1</version> 
    </dependency> 
    </dependencies> 
</project> 

에 집착 코어 종속성을 추가해야 문제를 해결하기 위해, 당신은 pom.xml 파일에 선언 종속성을 담당 위에서 maven이 모든 의존성을 포함하는 jar 파일을 다운로드하는 것을 보자.

import org.fourthline.cling.UpnpService; 
import org.fourthline.cling.UpnpServiceImpl; 
+0

이 또한 내 pom.xml 파일에없는 : – Jimbotron

1

내가 import 문을 잃어버린 사용 된 예를 것 같은데?