2012-11-11 3 views
0

Eclipse에서 maven-archetype-webapp 프로젝트를 만들었습니다. 그리고 Java에서 Clojure 코드를 사용하려고합니다. 그래서, 내 core.clj 파일이 있습니다 :java와 clojure를 사용하여 Eclipse에서 maven 동적 웹 프로젝트를 만들려고 시도했습니다.

(ns coq.core 
(:gen-class 
    :name coq.core 
    :methods [#^{:static true} [foo [int] void]])) 

(defn -foo [i] (println "Hello from Clojure. My input was " i)) 

(defn -main [] (println "Hello from Clojure -main.")) 

의 pom.xml :

: core.foo에 오류 내 하나의 서블릿 (123)

<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>gleboGroup</groupId> 
<artifactId>javaandclojure</artifactId> 
<packaging>war</packaging> 
<version>0.0.1-SNAPSHOT</version> 
<name>javaandclojure Maven Webapp</name> 
<url>http://maven.apache.org</url> 
<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.1-b02</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.clojure</groupId> 
     <artifactId>clojure</artifactId> 
     <version>1.3.0</version> 
    </dependency> 
</dependencies> 
<build> 
    <finalName>javaandclojure</finalName> 
    <plugins> 
     <plugin> 
      <groupId>com.theoryinpractise</groupId> 
      <artifactId>clojure-maven-plugin</artifactId> 
      <version>1.3.10</version> 
      <configuration> 
       <sourceDirectories> 
        <sourceDirectory>src/main/clojure</sourceDirectory> 
       </sourceDirectories> 
       <testSourceDirectories> 
        <testSourceDirectory>src/test/clojure</testSourceDirectory> 
       </testSourceDirectories> 
      </configuration> 
      <executions> 
       <execution> 
        <id>compile</id> 
        <phase>compile</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>test</id> 
        <phase>test</phase> 
        <goals> 
         <goal>test</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <executions> 
       <execution> 
        <id>default-compile</id> 
        <phase>compile</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>default-testCompile</id> 
        <phase>test-compile</phase> 
        <goals> 
         <goal>testCompile</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

있다

package com.javaandclojure; 

import java.io.IOException; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.ServletException; 
import javax.servlet.http.*; 

import coq.*; 

@WebServlet({ "/*"}) 
public class Main extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    protected void doGet(HttpServletRequest request, 
      HttpServletResponse response) throws ServletException, IOException { 
     System.out.println("inside get!"); 
     core.foo(123);// core cannot be resolved 
     request.setAttribute("number", 42); 
     request.getRequestDispatcher("/index.jsp").forward(request, response); 
    } 
} 

일식의 일부 scrinshots :

,

enter image description here

빌드 경로 :

enter image description here

Maven을 목표로 구축 : "깨끗한 패키지"를 제공합니다

[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building javaandclojure Maven Webapp 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ javaandclojure --- 
[INFO] Deleting D:\porn\indigo\javaandclojure\target 
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ javaandclojure --- 
[WARNING] Using platform encoding (Cp1251 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ javaandclojure --- 
[WARNING] File encoding has not been set, using platform encoding Cp1251, i.e. build is platform dependent! 
[INFO] Compiling 1 source file to D:\porn\indigo\javaandclojure\target\classes 
[INFO] ------------------------------------------------------------- 
[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] \porn\indigo\javaandclojure\src\main\java\com\javaandclojure\Main.java:[10,10] error: package coq does not exist 
[ERROR] \porn\indigo\javaandclojure\src\main\java\com\javaandclojure\Main.java:[17,2] error: cannot find symbol 
[INFO] 2 errors 
[INFO] ------------------------------------------------------------- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.042s 
[INFO] Finished at: Sun Nov 11 16:28:25 EET 2012 
[INFO] Final Memory: 8M/20M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project javaandclojure: Compilation failure: Compilation failure: 
[ERROR] \porn\indigo\javaandclojure\src\main\java\com\javaandclojure\Main.java:[10,10] error: package coq does not exist 
[ERROR] \porn\indigo\javaandclojure\src\main\java\com\javaandclojure\Main.java:[17,2] error: cannot find symbol 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

아마 다른 받는다는 원형을 사용해야?

+0

clojure가 생성하는 .class 파일을 보았습니까? – Cubic

+0

javaandclojure \ target \ javaandclojure \ WEB-INF \ classes \ coq \ 다음을 포함합니다 : core $ _foo.class, 코어 $ _main, 코어 $ loading__4505__auto __ 클래스, core.class, core__init.class, core.cls – Hlib

답변

2

Java 컴파일러가 clojure 컴파일러보다 먼저 실행되기 때문입니다.

clojure-maven-plugin 이후에 강제로 Java 컴파일이 수행되면 작동합니다.clojure-maven-plugin 후이 라인을 을 추가

<plugin> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>2.3.2</version> 
    <executions> 
     <execution> 
      <id>default-compile</id> 
      <phase>none</phase> 
     </execution> 
     <execution> 
      <id>default-testCompile</id> 
      <phase>none</phase> 
     </execution> 
     <execution> 
      <id>java-compile</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>compile</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>java-testCompile</id> 
      <phase>test-compile</phase> 
      <goals> 
       <goal>testCompile</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
+0

변경되었습니다. xml과 아무것도 변경되지 않았습니다. 글쎄 내가 바꿨어? – Hlib

+0

명령 줄에서'mvn compile'을 실행하면 그것이 작동하는 것을 볼 수 있습니다. 그 플러그인 구성이 없다면 나는 컴파일하지 않을 것을 제안했다. – maba

+0

이 오류없이 Eclipse에서 작업 할 수 없습니까? – Hlib

0

나는 무엇인지에 따라 달라집니다 분명한 있도록 2 개 모듈 프로젝트를 만들 것을 제안합니다. 자바 코드가 Clojure 코드에 의존해야한다면, java 모듈 (war?)은 clojure 모듈에 의존해야한다.

관련 문제