Maven 종속성으로서의 JDK tools.jar
JDK tools.jar을 컴파일 종속성으로 넣고 싶습니다. 다음과 같은 systemPath 속성 을 사용하는 것을 나타내는 몇 가지 예를 찾았습니다 .
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
문제는 경로가 Mac Os X에서는 올바르지 않다는 것입니다 (그러나 Windows 및 Linux에서는 정확함). 이를 위해 올바른 경로는 $ {java.home} /../ Classes / classes.jar 입니다.
시스템이 Mac Os X로 감지되면 값이 $ {java.home} /../ Classes / classes.jar 로 설정 되고 그렇지 않으면 $ 로 설정되도록 maven 속성을 정의하는 방법을 찾고 있습니다. {java.home} /../ lib / tools.jar (ANT로 할 수있는 것처럼). 누군가 아이디어가 있습니까?
이것이 프로필의 용도이며 속성에 대한 경로를 추출하고 Windows, OSX 등에 대한 프로필을 설정하고 속성 값을 적절하게 정의합니다.
다음은 OS 용 프로필을 설명하는 문서 페이지입니다. Maven 로컬 설정 모델
다음과 같이 표시되어야합니다.
<profiles>
<profile>
<id>windows_profile</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>osx_profile</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
메이븐 프로필을 소개 해주셔서 감사합니다.
위에서 언급 한대로 프로필을 사용하고 원하는 파일의 존재 여부에 따라 프로필을 활성화했습니다.
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
나는 이전 게시물에서 실수를 강조하기 위해이 답변을 게시했습니다 : 속성 섹션은 지정된 속성의 존재에 따라 프로필을 활성화하기 위해 활성화 섹션에서만 사용할 수 있습니다. 속성을 정의하기 위해서는 위와 같이 속성 섹션을 사용해야합니다.
안녕하세요, 여러분 모두 똑똑하다는 것을 알고 있지만, 그로 인해 며칠 동안 답변이 완전하지 않다는 것을 알게되었습니다. 프로필과 종속성이 모두 필요합니다. 아무도 이것에 다시 시간을 낭비하지 않기를 바랍니다. 아래의 전체 코드를 참조하십시오.
<profiles>
<profile>
<id>osx_profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
어떻게 든 Windows의 일식이 {java.home}을 선택하지 못합니다. 그래서 java.home 대신 JAVA_HOME을 설정해야했습니다. JAVA_HOME은 실행-> 구성 실행-> 환경에서 설정되었습니다. 이것은 표준 JDK (Apple JDK가 아님)에서 저에게 효과적이었습니다.
<profiles>
<profile>
<id>windows-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${JAVA_HOME}/lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${JAVA_HOME}/lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>jdk1.8.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
Q : JDK 9에서 작동하도록 tools.jar에 대한 maven 종속성 선언
As the actual maven wizardry is quite elaborate, surprising to newcomers and a subject of future improvements, it is better not co copy-paste it around. Hence this module exists so you do not have to know or care about the details. ~~ https://github.com/olivergondza/maven-jdk-tools-wrapper
<dependency>
<groupId>com.github.olivergondza</groupId>
<artifactId>maven-jdk-tools-wrapper</artifactId>
<version>0.1</version>
</dependency>
The comment of Edward is correct.
You need the profile AND you need the dependency
outside of the profiles
block. The profile just determines which value ${toolsjar}
is gonna get.
<dependencies>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>jdk1.8.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
Proper instructions for beginners
First Add this profile to Pom.xml file above tag or somewhere else in it.
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
then Correct JRE path
Goto :
Windows > Preferecnes > Installed JREs
selected intalled JRE and double click on it or from right menu click edit and then make sure JRE Home path is inside JDK something like:
C:\Program Files\Java\jdk1.8.0_181\jre
if you have installed JRE seperatly then eclipse would have picked standalone JRE like:
C:\Program Files\Java\jre1.8.0_181\
so change it to JRE which come with JDK:
C:\Program Files\Java\jdk1.8.0_181\jre
my solution:
- put the Sun's tools.jar to the
$JAVA_HOME/lib
- make a symlink in the
$JAVA_HOME/..
named lib where target will be$JAVA_HOME/lib
참고URL : https://stackoverflow.com/questions/3080437/jdk-tools-jar-as-maven-dependency
'Development Tip' 카테고리의 다른 글
Android Studio 2.0-플러그인이 너무 오래되었습니다. 최신 버전으로 업데이트하거나 ANDROID_DAILY_OVERRIDE 환경 변수를 (0) | 2020.10.25 |
---|---|
Google지도는 API 키를 어떻게 보호하나요? (0) | 2020.10.24 |
Akka의 Actor와 Scala의 Actor 모델의 차이점은 무엇입니까? (0) | 2020.10.24 |
API를 사용하여 기본 MailChimp 가입 양식 만들기 (0) | 2020.10.24 |
파이썬 추상 클래스에서 추상 속성을 만드는 방법 (0) | 2020.10.24 |