Jump to content

Recommended Posts

Posted

I use Sphinx4 in my mod and I don't know how to get it to be included in the builded jar file for my mod. Whenever I run the jar I get a NoClassDefFoundError for one of the classes from the library. How do I make my mod reference the jar and build it with the mod?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

The thing is that there are so many required classes that I have to basically copy the entire library. But several of the necessary classes need Apache Commons math classes. So I would have to use those too (and those use a bunch of stuff from the rest of the math library). But if I add this sphinx core and data jar files to the java build path, everything works fine. So do I copy all those classes into my project or is there another way?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Put the library in the libs folder found in your mod's folder, create one if it doesn't exist. So if your mod's root folder is called StuffAndThings, you need to put the library in StuffAndThings/libs. The end user will still need to download the library though.

Posted

Do you mean the folder that contains src/main or the src/main/Java/com/stuffandthings?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Do I reference those things by putting them in the java build path for Minecraft?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

You need to add them to Eclipse's build path.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ok I did that, but still nothing. I right clicked on Minecraft, then Properties, then added JARs to libraries, under Java Build Path. I have a libs folder in my root folder and both jar files are there, but I get the same error. Would I possibly need to add anything in the mcmod file? What am I doing wrong?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

If you simply want to use library (.jar) in your project - you do it like you did (if you did it right).

Throw library.jar anywhere (that is not /mods/) and add it to build path in eclipse.

Then you can use its methods. Note that if you want to use other mod as lib - you need dev release (deobfuscated), if you want to make direct references.

 

As to compiling - do you want to pack library within your mod or just compile your mod and add dependency (is that ilbrary a @Mod?)

1.7.10 is no longer supported by forge, you are on your own.

Posted

Not sure info:

If the library is not minecraft thingy (meaning it has no reference to any MC/forge code, eg: some Math library or DB), I belive you can just throw it into Mod.jar after you compile your mod. (library just needs to be added to build path on compilation).

 

If that is not enough (throwin it in is not) OR the library actually references MC/forge code and needs to be obfuscated within compilation then:

Sure info:

Use shadowJar - its a gradle option that will pack lib src with your mod.

On how to use it - google.

 

Note: I belive there was something on forge docs on this, BUT - docs have been wiped a while ago and it seems shadowing is no longer there.

EDIT

I found it (different docs): https://forgegradle.readthedocs.org/en/latest/cookbook/#shading

I forgot forgegradle != mcforge

EDIT 2

Managed to find actual example: https://github.com/shadowfacts/DiscordChat/blob/1.8.9/build.gradle

1.7.10 is no longer supported by forge, you are on your own.

Posted

So just throwing the libs into the folder then compressing it and renaming to make it a jar didn't work, if there was another way that I was supposed to do it let me know. As for shadowJar, does the example from Edit 2 show and example of how to use shadowJar? I can't interpret the stuff in build.gradle, it just makes no sense to me, so could you explain it?

 

Thanks

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Heh, that's my

build.gradle

, Ernio.

 

I'll break the important bits down for you:

 

plugins {
id "com.matthewprenger.cursegradle" version "1.0.6"
id "com.github.johnrengelman.shadow" version "1.2.2"
}

Includes the plugins in Gradle, the only one you need is the second one (

"com.github.johnrengelman.shadow"

).

 

shadowJar {
classifier = ""
relocate "com.mashape.unirest", "net.shadowfacts.discordchat.repack.com.mashape.unirest"
relocate "com.neovisionaries.ws.client", "net.shadowfacts.discordchat.repack.com.neovisionaries.ws.client"
relocate "com.sun.jna", "net.shadowfacts.discordchat.repack.com.sun.jna"
relocate "javax.sound", "net.shadowfacts.discordchat.repack.javax.sound"
relocate "javazoom", "net.shadowfacts.discordchat.repack.javazoom"
relocate "net.dv8tion.jda", "net.shadowfacts.discordchat.repack.net.dv8tion.jda"
relocate "net.sourceforge.jaad", "net.shadowfacts.discordchat.repack.net.sourceforge.jaad"
relocate "org.apache.commons.codec", "net.shadowfacts.discordchat.repack.org.apache.commons.codec"
relocate "org.apache.commons.lang3", "net.shadowfacts.discordchat.repack.org.apache.commons.lang3"
relocate "org.json", "net.shadowfacts.discordchat.repack.org.json"
relocate "org.kc7bfi.jflac", "net.shadowfacts.discordchat.repack.orgkc7bfi.jflac"
relocate "org.tritonus", "net.shadowfacts.discordchat.repack.org.tritonus"
relocate "tomp2p.opuswrapper", "net.shadowfacts.discordchat.repack.tomp2p.opuswrapper"

relocate "org.apache.http", "net.shadowfacts.discordchat.repack.org.apache.http"
relocate "org.apache.commons.logging", "net.shadowfacts.discordchat.repack.org.apache.commons.logging"

dependencies {
	include(dependency("net.dv8tion:JDA:1.2.2_167:withDependencies"))
}
}

This is the most important bit.

  • The
    classifier

    line sets the classifier to nothing, so it is named the same as the default jar.

  • All the
    relocate

    lines tell the Shadow plugin to move everything in those packages to different packages. This shouldn't be necessary unless:

    • You're repackaging something that's already required by MC/Forge (e.g. a new version of some library)
    • You're repackaging a library that's likely to be repackaged by other mods (to prevent conflicts)

     

    [*]The

    dependencies

    block tells Shadow specifically which dependency you want to include. You should replace

    "net.dv8tion:JDA:1.2.2_167:withDependencies"

    with the Maven identifier of the library you're shading.

     

     

reobf { shadowJar { mappingType = "SEARGE" } }
tasks.reobfShadowJar.mustRunAfter shadowJar

This bit tells ForgeGradle to reobfuscate the the jar that contains all the shaded libraries, otherwise your mod would crash instantly in a normal environment.

 

afterEvaluate {
tasks.curseforge240995.dependsOn reobfShadowJar
}

This bit is only necessary if you're using CurseGradle with Shadow. It tells CurseGradle not to upload the shadowJar until it has been reobfuscated. You'd need to replace

curseforge240995

with

curseforge

+ the ID number of your CurseForge project.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Posted

Is this the maven identifier?

 

compile group: 'edu.cmu.sphinx', name: 'sphinx4-core', version:'5prealpha-SNAPSHOT'
    compile group: 'edu.cmu.sphinx', name: 'sphinx4-data', version:'5prealpha-SNAPSHOT'

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Is this the maven identifier?

 

compile group: 'edu.cmu.sphinx', name: 'sphinx4-core', version:'5prealpha-SNAPSHOT'
    compile group: 'edu.cmu.sphinx', name: 'sphinx4-data', version:'5prealpha-SNAPSHOT'

 

I'd start by visiting the Maven site and searching for the library http://search.maven.org/#search%7Cga%7C1%7C

Then you can insert the various pieces GROUP, NAME, VERSION as shown on the site. If it's not on maven then you will need to figure out where it's hosted and add the site to the repositories.

 

Alternately you can use the flatDir option and place the jars in a folder someplace and still shadow them in.

partial build.gradle

repositories {
   flatDir {
       dirs 'xjars'
   }
}

dependencies {
// Shadow these jars then later we'll use the Shadow plugin to relocate them into our final jar
shadow name: "liquinth-a42" // a local jar in the project directory 'xjars' see repositories..flatDir stuff above.
}

shadowJar {
archiveName = tasks.jar.archiveName
relocate 'jvst.examples.liquinth', 'net.aeronica.shadowedlibs.liquinth'
}

reobfJar {
    setJar(tasks.shadowJar.archivePath)
}
reobfJar.dependsOn shadowJar

jar {
    configurations.shadow.each { dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}
jar.dependsOn shadowJar
jar.enabled = false

processResources
{
. . .
}

sourceSets {
    main.java.srcDirs += 'xjars'
}

Posted

Axlen, that's not what OP asked.

 

Is this the maven identifier?

 

compile group: 'edu.cmu.sphinx', name: 'sphinx4-core', version:'5prealpha-SNAPSHOT'
    compile group: 'edu.cmu.sphinx', name: 'sphinx4-data', version:'5prealpha-SNAPSHOT'

 

OP: Kind of. All those things combined are the maven identifier, using the pattern

"GROUP:NAME:VERSION"

. e.g. for sphinx4-core it would be

"edu.cmu.sphinx:sphinx4-core:5prealpha-SNAPSHOT"

. The one for sphinx4-data is assembled in the same pattern.

 

You will need of the

include(dependency("..."))

because you have two separate dependencies.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Posted

So when I build it, I get this error:

 

 

Download https://plugins.gradle.org/m2/com/github/jengelman/gradle/plugins/shadow/1.2.2/shadow-1.2.2.pom
Download https://plugins.gradle.org/m2/org/jdom/jdom2/2.0.5/jdom2-2.0.5.pom
Download https://plugins.gradle.org/m2/org/ow2/asm/asm/5.0.3/asm-5.0.3.pom
Download https://plugins.gradle.org/m2/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.pom
Download https://plugins.gradle.org/m2/org/apache/ant/ant/1.9.4/ant-1.9.4.pom
Download https://plugins.gradle.org/m2/org/apache/ant/ant-parent/1.9.4/ant-parent-1.9.4.pom
Download https://plugins.gradle.org/m2/org/codehaus/plexus/plexus-utils/2.0.6/plexus-utils-2.0.6.pom
Download https://plugins.gradle.org/m2/org/codehaus/plexus/plexus/2.0.7/plexus-2.0.7.pom
Download https://plugins.gradle.org/m2/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.pom
Download https://plugins.gradle.org/m2/org/apache/ant/ant-launcher/1.9.4/ant-launcher-1.9.4.pom
Download https://plugins.gradle.org/m2/com/github/jengelman/gradle/plugins/shadow/1.2.2/shadow-1.2.2.jar
Download https://plugins.gradle.org/m2/org/jdom/jdom2/2.0.5/jdom2-2.0.5.jar
Download https://plugins.gradle.org/m2/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar
Download https://plugins.gradle.org/m2/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.jar
Download https://plugins.gradle.org/m2/org/apache/ant/ant/1.9.4/ant-1.9.4.jar
Download https://plugins.gradle.org/m2/org/codehaus/plexus/plexus-utils/2.0.6/plexus-utils-2.0.6.jar
Download https://plugins.gradle.org/m2/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar
Download https://plugins.gradle.org/m2/org/apache/ant/ant-launcher/1.9.4/ant-launcher-1.9.4.jar

FAILURE: Build failed with an exception.

* What went wrong:
org.gradle.api.plugins.JavaPlugin

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 30.714 secs

 

 

Here is my build.grade:

 

buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'

    }
}

plugins{
id "com.github.johnrengelman.shadow" version "1.2.2"
}

apply plugin: 'forge'

version = "1.0"
group= "com.apmods.hpspells" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "hpspells"

minecraft {
    version = "1.7.10-10.13.4.1614-1.7.10"
    runDir = "eclipse"
}


dependencies {

}

processResources
{
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
                
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
        
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

shadowJar {
classifier=""
dependencies{
	include(dependency("edu.cmu.sphinx:sphinx4-core:5prealpha-SNAPSHOT"))
	include(dependency("edu.cmu.sphinx:sphinx4-core:5prealpha-SNAPSHOT"))
}
}

reobf {
shadowJar{
	mappingType="SEARGE"
}
}
tasks.reobfShadowJar.mustRunAfter shadowJar

 

 

Not sure what the error is.

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

I don't believe the forge gradle use in the 1.7.10 branch supports this part of the file.

reobf {
shadowJar{
	mappingType="SEARGE"
}
}
tasks.reobfShadowJar.mustRunAfter shadowJar

 

I originally starting working with shadowed libs in 1.8.x and when I back ported some code I had to remove that section.

 

Here's the build.gradle I'm using that works for me.

buildscript {
    repositories {
	jcenter()
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
	classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2'
    }
}
apply plugin: 'forge'
apply plugin: 'java' // or 'groovy'. Must be explicitly applied
apply plugin: 'com.github.johnrengelman.shadow'

//Set the mod version, is appended to the end of the jar name
version = "1.7.10-2016.03.20"
group = "net.aeronica.mods.mcjammer" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
// Set the jar name as the project root folder name
archivesBaseName = "mcjammer"

configurations {
    shadow
    compile.extendsFrom shadow
}

minecraft {
    version = "1.7.10-10.13.4.1614-1.7.10"
    // version = "1.7.10-10.13.1.1225"
    runDir = "run"
}

dependencies {
// Shadow these jars then later we'll use the Shadow plugin to relocate them into our final jar
shadow "org.antlr:antlr4-runtime:4.5.2-1" // use ANTLR version 4	
}

shadowJar {
archiveName = tasks.jar.archiveName
configurations = [project.configurations.shadow]
relocate 'org.antlr.v4.runtime', 'net.aeronica.shadowedlibs.org.antlr.v4.runtime' 
}

jar {
    configurations.shadow.each { dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}
jar.dependsOn shadowJar
jar.enabled = false

processResources
{
    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'

        // replace version and mcversion
	    expand 'version':project.version, 'mcversion':project.minecraft.version
    }

    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

 

Sorry about my previous post, shadowfacts is correct I really did not answer your question properly. Finding concise answers regarding the format and values to use was difficult for me too. There is a lot of information about Maven, Gradle and whole gaggle ways to build code. The cold hard facts and reams of documentation tend to make my eyes glaze over. Working examples that do useful things are best, but not always easy to find.

 

Fortunately there are many very knowledgeable and helpful people on these forums to help guide the rest of us into the light. I'm amazed at the dedication of the Forge forum moderators and developers who continue to press forward despite the fact that the world of Minecraft and modding is an ever changing landscape.

Posted

Is the relocate necessary? If so, how do I know the name of the thing I relocate, because the jar you relocate (relocate 'name') is not the same as the maven identifier.

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Is the relocate necessary? If so, how do I know the name of the thing I relocate, because the jar you relocate (relocate 'name') is not the same as the maven identifier.

 

The relocation is the real magic of the shadow plugin. It changes the path of the classes so they won't conflict another mod that might use the same library or a different version of the same library.

 

But to answer your question, no you don't have to relocate the library if you don't want to. I've seen other mod authors include libraries without any relocation, but I consider it a bad practice.

 

shadowJar {
archiveName = tasks.jar.archiveName
configurations = [project.configurations.shadow]
relocate 'org.antlr.v4.runtime', 'net.aeronica.shadowedlibs.org.antlr.v4.runtime' 
}

 

Here's what the mcjammer mod jar looks like inside

o2TCi.png

 

9ce8b1dc1b.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.