Install/Usage Overview

You can use JUnion:

Source Translator

You can compile java source with junion with the following command:

java -jar junionc1.0.jar -classpath lib/junion1.0.jar -version 1.8 -sourcepath src -outputpath out

where:

Javac plugin

You can compile JUnion project directly with javac 1.8, by adding a command line argument: -Xplugin:junion. Make sure all the referenced libraries are on the classpath.

Eclipse plugin

To use JUnion within Eclipse IDE, follow the steps:

  1. Open Eclipse
  2. Help -> Install New Software
  3. Enter eclipse update site: https://tehleo.github.io/junion/update
  4. Select JUnion plugin and continue with the installation.

  5. Create new Java Project or Open existing one
  6. Add project runtime library: junion<version>.jar
  7. Create new file in the project named “.junion”
  8. In .junion property file, set property compileLibs= path to junionc<version>.jar
  9. Instead of step 4. you can add library junionc<version>.jar directly to your classpath. However it is not a runtime dependency.
  10. Save the file, this should automatically create the folder “.generated_src_junion” (If you do not see files beginning with a dot, your package explorer has a filter enabled)
  11. In project properties -> Java Build Path -> Sources -> Add Folder and add .generated_src_junion
  12. Window -> Preferences -> Java -> Compiler -> Error/Warnings -> Deprecated or Restricted API Set Forbidden Reference to Warning.

Alternatively watch the Eclipse Setup Tutorial:

Eclipse Installation Tutorial

Netbeans Support

To use JUnion within Netbean IDE, follow the steps:

  1. Add all the libraries to the project.
  2. Project Properties -> Build -> Compiling -> Disable Compile on Save and enter “-Xplugin:junion” in Additional Compiler Options

Gradle

Gradle build file:

apply plugin: 'java'

repositories {
    mavenCentral()
}
configurations {
    junion
}
dependencies {
    compile 'com.github.tehleo:junion:1.1.1'
    junion 'com.github.tehleo:junionc:1.1.1'
}
task junionTask(type: JavaExec) {
    classpath configurations.junion
    classpath += sourceSets.main.runtimeClasspath
    main = 'theleo.jstruct.plugin.SourceCompiler'
    args = ['-classpath', sourceSets.main.runtimeClasspath.getAsPath(),
            '-version', '1.8',
            '-sourcepath', files(sourceSets.main.java.srcDirs).getAsPath(),
            '-outputpath', file('build/generated').getPath()
    ]
   	sourceSets.main.java.srcDirs = ['build/generated']
}

build.dependsOn junionTask

Maven

Maven build file:

<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>

	<groupId>tehleo.maventest</groupId>
	<artifactId>test</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>jar</packaging>

	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	 </properties>

 	 <name>Hello Structs</name>
 
	<dependencies>
		<dependency>
			<groupId>com.github.tehleo</groupId>
			<artifactId>junion</artifactId>					
			<version>1.1.1</version>
		</dependency>
	</dependencies>

	<build>
		<sourceDirectory>${basedir}/target/generated-sources</sourceDirectory>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>build-classpath</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>build-classpath</goal>
						</goals>
						<configuration>
							<outputProperty>classpath-string</outputProperty>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>exec-maven-plugin</artifactId>
			<version>1.6.0</version>
			<executions>
				<execution>
				<phase>generate-sources</phase>
				<goals>
					<goal>java</goal>
				</goals>
				</execution>
			</executions>
			<configuration>
				<includePluginDependencies>true</includePluginDependencies>
				<mainClass>theleo.jstruct.plugin.SourceCompiler</mainClass>
				<sourceRoot>${basedir}/target/generated-sources</sourceRoot>
				<arguments>
					<argument>-noSystemExitOnSuccess</argument>
					<argument>-classpath</argument>
					<argument>${classpath-string}</argument>
					<argument>-version</argument>
					<argument>1.8</argument>
					<argument>-sourcepath</argument>
					<argument>${basedir}/src/main</argument>
					<argument>-outputpath</argument>
					<argument>${basedir}/target/generated-sources</argument>
				</arguments>
			</configuration>
			<dependencies>
				<dependency>
				<groupId>com.github.tehleo</groupId>
				<artifactId>junionc</artifactId>
				<version>1.1.1</version>
				</dependency>
			</dependencies>
			</plugin>
		</plugins>
	</build>
</project>