Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding an external Dependency to my maven-tycho build
Adding an external Dependency to my maven-tycho build [message #1785774] Thu, 19 April 2018 14:40 Go to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Hello,

I am having trouble to add a dependency to an external java library via maven in my maven-tycho build.

This is my Environment:


  • Windows 7 x64
  • Xtext 2.12
  • Eclipse oxygen


I created the example project using the project wizard. I checked the eclipseplugin, support for testing, selected the maven build system and used the plain source layout.

Then i ran mvn install on the /org.xtext.example.mydsl project. The build was successfull.

Then i used a json library in the generator :
/*
 * generated by Xtext 2.12.0.M1
 */
package org.xtext.example.mydsl.generator

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.json.JSONObject

/**
 * Generates code from your model files on save.
 * 
 * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
 */
class MyDslGenerator extends AbstractGenerator {

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
	val myString = new JSONObject()
          .put("JSON", "Hello, World!").toString();
	}
}


If I run the same mvn install now i get an error as expected. The error is raised during the xtend compilation
[INFO] --- xtend-maven-plugin:2.12.0.M1:compile (default) @ org.xtext.example.mydsl ---
[ERROR] 
ERROR: 	MyDslGenerator.xtend - D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
10: org.json.JSONObject cannot be resolved to a type.
[ERROR] 
ERROR: 	MyDslGenerator.xtend - D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
20: JSONObject cannot be resolved.


Then i added the dependency into the /org.xtext.example.mydsl/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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.xtext.example.mydsl</groupId>
		<artifactId>org.xtext.example.mydsl.parent</artifactId>
		<version>1.0.0-SNAPSHOT</version>
	</parent>
	<artifactId>org.xtext.example.mydsl</artifactId>
	<packaging>eclipse-plugin</packaging>

	<dependencies>
		<dependency>
			<groupId>org.json</groupId>
			<artifactId>json</artifactId>
			<version>20180130</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
...


Now the build fails in a later phase, where the java sources are compiled:
ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile (default-compile) on project org.xtext.example.mydsl: Compilation failure: Compilation failure:
[ERROR] D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\xtend-gen\org\xtext\example\mydsl\generator\MyDslGenerator.java:[10]
[ERROR] import org.json.JSONObject;
[ERROR] ^^^^^^^^
[ERROR] The import org.json cannot be resolved
[ERROR] D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\xtend-gen\org\xtext\example\mydsl\generator\MyDslGenerator.java:[21]
[ERROR] final String myString = new JSONObject().put("JSON", "Hello, World!").toString();
[ERROR] ^^^^^^^^^^
[ERROR] JSONObject cannot be resolved to a type
[ERROR] 2 problems (2 errors)


If somebody knows where in the pom and how the dependency should be added I would be very thannkfull if he or she could drop me a hint. Or do I have to make some adjustments to the manifest.mf?

It seems to ba a fairly standard question but unfortunately I did not find any answers on google.

Tahanks in advance,

Lukas
Re: Adding an external Dependency to my maven-tycho build [message #1785777 is a reply to message #1785774] Thu, 19 April 2018 15:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
is there are reason you dont use json a a p2 dependency in target platform consuming http://download.eclipse.org/tools/orbit/downloads/drops/R20180330011457/ (repo url = http://download.eclipse.org/tools/orbit/downloads/drops/R20180330011457/repository)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding an external Dependency to my maven-tycho build [message #1785961 is a reply to message #1785777] Mon, 23 April 2018 15:06 Go to previous messageGo to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Thanks for your hint Christian.

I managed to add the repository in the target project like so (Don't be confused by the different dependencies. These were the dependencies my project actually neede. Json was just an example):

*.target/target.target
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.apache.poi" version="0.0.0"/>
<unit id="org.apache.poi.ooxml" version="0.0.0"/>
<unit id="org.apache.poi.ooxml.schemas" version="0.0.0"/>
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20180330011457/repository"/>
</location>


I still had to adjustthe MANIFEST.MF in the required bundles sections in the project that uses the dependency. Unfortunately the editor does not recognize these bundles and shows an error. Also Eclipse does not recognize the dependencies either. Hence I have errors in my Project using eclipse. But I can build my Project with Maven perfectly.

If you have any hints how eclipse recognizes the dependencies, please let me know.
Re: Adding an external Dependency to my maven-tycho build [message #1785966 is a reply to message #1785961] Mon, 23 April 2018 15:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
you need to reset/reload your target platform before you start runtime eclipse

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding an external Dependency to my maven-tycho build [message #1786026 is a reply to message #1785966] Tue, 24 April 2018 09:50 Go to previous message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
ok got it! :) Thank you again.
Previous Topic:Dynamic scoping based on ecore reflection and information in the runtime
Next Topic:Formatter is discarding empty lines between comments
Goto Forum:
  


Current Time: Tue Apr 16 11:29:25 GMT 2024

Powered by FUDForum. Page generated in 1.21265 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top