Programing

명령 행에서 Eclipse Java 프로젝트 빌드

lottogame 2020. 7. 20. 20:34
반응형

명령 행에서 Eclipse Java 프로젝트 빌드


명령 행에서 Eclipse 기반 Java 프로젝트를 컴파일하는 방법이 있습니까?

FinalBuilder를 사용하지 않고 빌드를 자동화하려고하는데 Java 또는 Eclipse 전문가가 아닙니다. Java 명령 행 옵션을 사용 하여이 작업을 수행하는 방법을 알아낼 수는 있지만 Eclipse 프로젝트는 많은 노력을 낭비하는 것처럼 느껴집니다.

명령 행을 통해 Eclipse 프로젝트를 컴파일 할 방법이없는 경우 Eclipse 내에서 필수 java 명령 행을 생성하는 방법이 있습니까? 아니면 뒤에서 수행하는 컴파일 단계를 찾기 위해 찌를 수있는 파일이 있습니까?


여러분, 나는 개미를 포함 하지 않는 답변을 찾고 있습니다. 원래 질문을 다시 반복하겠습니다 .... 명령 행에서 Eclipse 프로젝트를 빌드하는 방법이 있습니까?

Visual Studio에서 이와 같은 작업을 수행 할 수 있다는 점에서 이것이 부당한 질문이라고 생각하지 않습니다.

devenv.exe /build "Debug|Any CPU" "C:\Projects\MyProject\source\MyProject.sln"

명령 행에서 작업 공간을 통해 이클립스 프로젝트를 빌드 할 수 있습니다.

eclipsec.exe -noSplash -data "D:\Source\MyProject\workspace" -application org.eclipse.jdt.apt.core.aptBuild

그것은 사용하여 jdt apt자동으로 작업 공간을 구축하는 플러그인. 이것은 '헤드리스 빌드'라고도합니다. 알아 내기 힘들다. win32 exe를 사용하지 않는 경우 다음을 시도하십시오.

java -cp startup.jar -noSplash -data "D:\Source\MyProject\workspace" -application org.eclipse.jdt.apt.core.aptBuild

최신 정보

몇 년 전에 일식 startup.jar은 "춘분 발사기" 로 대체

https://wiki.eclipse.org/Equinox_Launcher

Eclipse Mars (MacOX)에서 :

java -jar /Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar -noSplash -data "workspace" -application org.eclipse.jdt.apt.core.aptBuild

-data매개 변수는 작업 공간의 위치를 ​​지정합니다.

춘분 실행기의 버전 번호는 사용중인 Eclipse 버전에 따라 다릅니다.


André의 답변을 완성하기 위해 개미 솔루션은 다음과 같이 Emacs, JDEE, Ant 및 Eclipse Java Compiler에 설명 된 것과 유사 할 수 있습니다 .

      <javac
          srcdir="${src}"
          destdir="${build.dir}/classes"> 
        <compilerarg 
           compiler="org.eclipse.jdt.core.JDTCompilerAdapter" 
           line="-warn:+unused -Xemacs"/>
        <classpath refid="compile.classpath" />
      </javac>

compilerarg 요소를 사용하면 추가 명령 행 인수를 Eclipse 컴파일러로 전달할 수도 있습니다.

다음 과 같이 명령 행에서 호출 되는 전체 개미 스크립트 예제를 찾을 수 있습니다 .

java -cp C:/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar org.eclipse.core.launcher.Main -data "C:\Documents and Settings\Administrator\workspace" -application org.eclipse.ant.core.antRunner -buildfile build.xml -verbose

그러나 개미와 관련된 모든 것은 Keith가 추구하는 것이 아닙니다.

일괄 컴파일의 경우, 참조하시기 바랍니다 자바 코드 컴파일 , 특히 "절 배치 컴파일러 사용을 "

일괄 처리 컴파일러 클래스는 JDT 코어 플러그인에 있습니다. 클래스 이름은 org.eclipse.jdt.compiler.batch.BatchCompiler입니다. plugins / org.eclipse.jdt.core_3.4.0..jar에 패키지되어 있습니다. 3.2 이후로 별도의 다운로드로도 제공됩니다. 파일 이름은 ecj.jar입니다.
3.3 이후이 jar에는 jsr199 (컴파일러 API) 및 jsr269 (주석 처리)에 대한 지원도 포함됩니다. 주석 처리 지원을 사용하려면 1.6 VM이 필요합니다.

명령 행에서 배치 컴파일러 실행

java -jar org.eclipse.jdt.core_3.4.0<qualifier>.jar -classpath rt.jar A.java

또는:

java -jar ecj.jar -classpath rt.jar A.java

모든 Java 컴파일 옵션도 해당 섹션에 자세히 설명되어 있습니다.

Visual Studio 명령 행 컴파일 기능의 차이점은 Eclipse가 명령 행 인수에서 .project 및 .classpath를 직접 읽지 않는 것 입니다. 매우 동일한 컴파일 결과를 얻으려면 .project 및 .classpath에 포함 된 모든 정보를 다양한 명령 줄 옵션으로보고해야합니다.

그래서 짧은 대답은 "예, 이클립스 종류의 것"입니다. ;)


27 년이 지난 후에도 IDE에서 개발하는 것이 불편합니다. 나는 위의 제안을 시도했다. 아마도 모든 것을 제대로 따르지 않았다. 그래서 웹 검색을하고 ' http://incise.org/android-development-on-the- command-line.html '.

답변은 위의 모든 답변을 조합 한 것으로 보입니다 (잘못되면 알려주고 사과를 받아주십시오).

위에서 언급했듯이 eclipse / adt는 필요한 개미 파일을 만들지 않습니다. 일식 IDE없이 (및 개미 스크립트를 작성하지 않고) 컴파일하려면 다음을 수행하십시오.

1) 최상위 디렉토리에 build.xml을 생성하십시오.

android list targets  (to get target id used below)

android update project --target target_id --name project_name  --path top_level_directory

   ** my sample project had a target_id of 1 and a project name of 't1', and 
   I am building from the top level directory of project
   my command line looks like android update project --target 1 --name t1 --path `pwd`

2) 다음으로 프로젝트를 컴파일합니다. 'ant'를 사용하지 않기로 한 요청에 약간 혼란 스러웠습니다. 바라건대-요청자는 자신이 개미 스크립트를 작성하고 싶지 않다는 것을 의미했습니다. 다음 단계는 ant를 사용하여 응용 프로그램을 컴파일하는 것이므로 이것을 말합니다.

 ant target

    this confused me a little bit, because i thought they were talking about the
    android device, but they're not.  It's the mode  (debug/release)
    my command line looks like  ant debug

3) APK를 장치에 설치하려면 개미를 다시 사용해야했습니다.

 ant target install

    ** my command line looked like  ant debug install

4) 내 안드로이드 폰에서 프로젝트를 실행하려면 adb를 사용하십시오.

 adb shell 'am start -n your.project.name/.activity'

    ** Again there was some confusion as to what exactly I had to use for project 
    My command line looked like adb shell 'am start -n com.example.t1/.MainActivity'
    I also found that if you type 'adb shell' you get put to a cli shell interface
    where you can do just about anything from there.

3A) 참고 : 장치에서 로그를 보려면 다음을 사용하십시오.

 adb logcat

3B) 두 번째 측면 참고 : 위에서 언급 한 링크에는 명령으로 전체 프로젝트를 빌드하기위한 지침도 포함되어 있습니다.

Hopefully, this will help with the question. I know I was really happy to find anything about this topic here.


The normal apporoach works the other way around: You create your build based upon maven or ant and then use integrations for your IDE of choice so that you are independent from it, which is esp. important when you try to bring new team members up to speed or use a contious integration server for automated builds. I recommend to use maven and let it do the heavy lifting for you. Create a pom file and generate the eclipse project via mvn eclipse:eclipse. HTH


This question contains some useful links on headless builds, but they are mostly geared towards building plugins. I'm not sure how much of it can be applied to pure Java projects.


Just wanted to add my two cents to this. I tried doing as @Kieveli suggested for non win32 (repeated below) but it didn't work for me (on CentOS with Eclipse: Luna):

java -cp startup.jar -noSplash -data "D:\Source\MyProject\workspace" -application org.eclipse.jdt.apt.core.aptBuild

On my particular setup on CentOS using Eclipse (Luna) this worked:

$ECLIPSE_HOME/eclipse -nosplash -application org.eclipse.jdt.apt.core.aptBuild  startup.jar -data ~/workspace

The output should look something like this:

Building workspace
Building '/RemoteSystemsTempFiles'
Building '/test'
Invoking 'Java Builder' on '/test'.
Cleaning output folder for test
Build done
Building workspace
Building '/RemoteSystemsTempFiles'
Building '/test'
Invoking 'Java Builder' on '/test'.
Preparing to build test
Cleaning output folder for test
Copying resources to the output folder
Analyzing sources
Compiling test/src/com/company/test/tool
Build done

Not quite sure why it apparently did it twice, but it seems to work.


Hi Just addition to VonC comments. I am using ecj compiler to compile my project. it was throwing expcetion that some of the classes are not found. But the project was bulding fine with javac compiler.

So just I added the classes into the classpath(which we have to pass as argument) and now its working fine... :)

Kulbir Singh


Short answer. No. Eclipse does not have a command line switch like Visual Studio to build a project.

참고URL : https://stackoverflow.com/questions/206473/build-eclipse-java-project-from-command-line

반응형