Trouble with JAR creation - java

sorry if this is a simple question but I'm having trouble exporting my java project into a JAR file. I'm getting the following error:
JAR creation failed. See details for additional information.
com/appiancorp/plugins/capitalize/theFunction [in Capitalize] is not on its project's build path
Unable to get package fragment root: Capitalize/com/appiancorp/plugins/capitalize/theFunction/Capitalize.java
com/appiancorp/plugins/capitalize/theFunction [in Capitalize] is not on its project's build path
I guess I need to add the "theFunction" class to my buildpath? But I don't understand how to do that...Thanks for the help
EDIT:
I'm using files from the StringTokenizer class in my project and thus importing stuff from java.util.StringTokenizer. Could the problem be I'm not adding that class to the JAR files?
Darby

The missing class belongs to a jar from the company(3d party)
http://www.appian.com/
you need to find that missing jar and add it to class path

Related

Export custom library to importable jar file java

I have created a custom package in Java. The directory structure is like this:-
wolpha
/Stream>Stream.java
/Word/Stream.java
/Pattern/Stream.java
/Stream/Stream.java
So I just made a non runnable jar file and tried to import the package but it gave a error that the package wolpha does not exist. Tried with a main class with imports included but gave the same error.
How can I add all these classes into a single .jar file such that all classes can be imported into any file. I expect some step-by-step instructions with some down-to-earth language.
If you are using eclipse, go to File > Export and follow the instructions as per the screenshots given below:

JavaFX: Need help understanding project hierarchy issues

My code has gotten quite large and so I've decided to build a runnable JAR to see how it's done. I probably should've tried sooner because I'm getting 2 different errors related to the project structure, first is the "no main manifest attribute error" when trying to run the JAR from command prompt. Double-clicking the JAR does nothing (Win7). The second issue is related to the FXMLLoader explained lower down.
I followed the steps here to build the JAR, which involved moving all Maven files into the JAR directory. The compiled JAR gave me the manifest error, so I followed this which adds a Maven plugin in my pom.xml file. The error might be caused by a wrong naming convention with the line <mainClass>com.primary.Drag</mainClass> where primary is the package and Drag is my Drag.java file (class) which has the main method.
Inititally I was using the default package but read that this is not recommended for larger projects, so I put all my files into "primary". Here is my current hierarchy as shown in IntelliJ:
The problem is that ever since I created the "primary" package, I can no longer even compile the program via IntelliJ, let alone build a runnable JAR. This is due by the second error I mentioned, which is java.lang.IllegalStateException: Location is not set. on this line within primary/Drag.java:
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("firstlaunch.fxml")); It used to work with the default package, but not anymore.
I tried replacing firstlaunch.fxml with /primary/firstlaunch.fxml and /resources/firstlaunch.fxml (with and without moving resources into primary package) but no luck.
3 Related Questions:
Is my project structure incorrect?
How do I reference the fxml file from the primary package?
Is this what I should write in Maven's mainClass tags? <mainClass>com.primary.Drag</mainClass>
Is my project structure incorrect?
Answer:
Your package name should be like com.primary.******
How do I reference the fxml file from theprimary package?
Answer:
Always make sure that you are trying to load firstlaunch .xml from the class which is located in same package where that xml is kept. Means class which you wrote the loading code and xml file should be in same package
Is this what I should write in Maven's mainClass tags?com.primary.Drag
Answer:
If you package name corrected to com.primary , your main class Drag will correctly added by maven

Getting 'Source not found' for class in Eclipse debug

My top level debug class as specified in the debug configuration is MyDebugClass. Further down in the main, it attempts to launch an instance of class ProblemClass that is in the same package as MyDebugClass but it errors out on the constructor invocation line saying "Source not found". The project compiles fine and the .class file is indeed in the target directory, the same place as the .class for MyDebugClass.
I thought there may have been something odd with the classpath so that the same package where the debug main is not included so I made a test class in the same directory and tried to invoke an instance of it and that worked. So that is not the problem.
I also added the following code in MyDebugClass.main to try to debug the issue:
ClassLoader loader = ProblemClass.class.getClassLoader();
Class probCls = loader.loadClass("mypackage.ProblemClass");
//here below is where it errors out
probCls.newInstance();
What could possibly be causing this kind of class loading problem? There is a whole bunch of jars in the classpath so could it be that one of them contains this same class qualifier and the class loader is trying to pick it up from there and not the target directory as specified in the debug build path? How do I find from where the class loader is attempting to load a class, e.g. file system path looking for a .class file or some jar?
Look at the file in the Eclipse "Package Explorer" view. That may give you some help. Also, you say that the .class file is in the target directory, but what about the source .java file?
Other things to check are the Java Build Path of your project properties.
I hope this helps, though you didn't really give enough detail to be able to understand what's really going on.

How to add a class to a .jar library?

I need to add a class to a .jar library but I can't figure out how to do it.
I have a library named netty-3.1.5.GA.jar but for some reason its missing a class I need
(HttpTunnelClientChannelFactory.java).
I have found that class on a repository but not as part of the library. So how can I 'inject' it? The class I need to add is using other classes that exist in the library.
You don't need to add it to the jar, you need to add it to the classpath of whatever it is you're running.
You can use the jar tool to update the jar file: you will need to manually create the appropriate package directory though. Try this:
jar uf netty-3.1.5.GA.jar HttpTunnelClientChannelFactory.class
will add it to the root package. If you need it to be set up in a package directory you should create the directory structure and then add the file with a path.
EDIT: that should be .class, not .java.

How can i load a class from another project using ClassLoader

i want to access a class from another project in the workspace using ClassLoader. How can i specify the path to that class and get that class file ?I am using Eclipse . Help
You have to just add that project in to build path configuration of the project where you want to access that. And the class loader will find that class depending on the import statement you have given in the class where you are using it.
To add in the build path : you have to right click on the project > select Build Path > Configure Build Path > then select a project tab and add the project in which the class is present which you want load.
You could try URLClassLoader an example is here
I never used GNU Classpath which could be heplful.
While I'm sure there are devious ways of doing exactly that, I think having one project reference another this way is not the best of ideas.
What you can do is create a jar of the project you're getting the class from via Export->Java->JAR file and put that file into your project. This will let you access the class you need while still keeping your projects self-contained.

Categories

Resources