Asweez Posted March 28, 2016 Share Posted March 28, 2016 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? Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
DestinySpork Posted March 28, 2016 Share Posted March 28, 2016 Maybe this page will help you, I assume you are talking about the Speech Recognition: http://cmusphinx.sourceforge.net/wiki/tutorialsphinx4 The API link doesn't work though so you may have to copy bits of code that you need. Quote Link to comment Share on other sites More sharing options...
Asweez Posted March 28, 2016 Author Share Posted March 28, 2016 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? Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Leviathan143 Posted March 28, 2016 Share Posted March 28, 2016 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. Quote Link to comment Share on other sites More sharing options...
Asweez Posted March 28, 2016 Author Share Posted March 28, 2016 Do you mean the folder that contains src/main or the src/main/Java/com/stuffandthings? Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Leviathan143 Posted March 28, 2016 Share Posted March 28, 2016 The one that contains src/main Quote Link to comment Share on other sites More sharing options...
Asweez Posted March 28, 2016 Author Share Posted March 28, 2016 Do I reference those things by putting them in the java build path for Minecraft? Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Asweez Posted March 29, 2016 Author Share Posted March 29, 2016 Tried doing that, didn't work. Still get NoClassDefFound error Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Asweez Posted March 29, 2016 Author Share Posted March 29, 2016 Bump Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Draco18s Posted March 29, 2016 Share Posted March 29, 2016 You need to add them to Eclipse's build path. Quote 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. Link to comment Share on other sites More sharing options...
Asweez Posted March 29, 2016 Author Share Posted March 29, 2016 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? Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Ernio Posted March 29, 2016 Share Posted March 29, 2016 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?) Quote 1.7.10 is no longer supported by forge, you are on your own. Link to comment Share on other sites More sharing options...
Asweez Posted March 30, 2016 Author Share Posted March 30, 2016 No it's not a @Mod, and I want to include it in my compiled mod. Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Ernio Posted March 30, 2016 Share Posted March 30, 2016 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 Quote 1.7.10 is no longer supported by forge, you are on your own. Link to comment Share on other sites More sharing options...
Asweez Posted March 30, 2016 Author Share Posted March 30, 2016 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 Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
shadowfacts Posted March 30, 2016 Share Posted March 30, 2016 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. Quote Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods Link to comment Share on other sites More sharing options...
Asweez Posted March 31, 2016 Author Share Posted March 31, 2016 Thanks! What is the maven identifier? Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Asweez Posted April 1, 2016 Author Share Posted April 1, 2016 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' Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Asweez Posted April 1, 2016 Author Share Posted April 1, 2016 Bump Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Aeronica Posted April 1, 2016 Share Posted April 1, 2016 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' } Quote Link to comment Share on other sites More sharing options...
shadowfacts Posted April 1, 2016 Share Posted April 1, 2016 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. Quote Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods Link to comment Share on other sites More sharing options...
Asweez Posted April 1, 2016 Author Share Posted April 1, 2016 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. Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Aeronica Posted April 2, 2016 Share Posted April 2, 2016 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. Quote Link to comment Share on other sites More sharing options...
Asweez Posted April 2, 2016 Author Share Posted April 2, 2016 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. Quote Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod. Link to comment Share on other sites More sharing options...
Aeronica Posted April 2, 2016 Share Posted April 2, 2016 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.