I have a project in eclipse. It does everything I want it to do when I click on the green circle play button in the IDE - opens the window, plays the stuff, everything. But, try as I might, I cannot figure out how to get it to do that outside of eclipse.
My project uses the processing.core library to do some of its stuff, but I am unable to get the project to function in the Processing IDE, because of some stupid stuff about one of my classes not being a valid substitute for the type parameter for Collections.sort(List<T>). If anyone knows how I can get it to export from the Processing IDE, that would be excellent.
I need to be able to email/upload to the internet/otherwise transmit some kind of file/folder/webpage that allows the recipient to, without much technical knowledge or work on their part, view a window or something that allows them to view and interact with the program in the same way I am able to interact with the window that Eclipse launches when I press the play button at the top.
I have tried several different ways of accomplishing this, but none of them have worked. I tried exporting a runnable .jar, but it wouldn't let me include the referenced libraries. I tried a regular .jar, but I don't know how to package that up with whatever is needed to be able to view it. I've even tried using the fat jar eclipse plugin for it, too, but I ran afoul of something about being unable to find the main PApplet class for the project.
If anybody knows how to get what I want to happen, or knows of a good tutorial on how to do what I want, I would greatly appreciate any sort of assistance or guidance or anything.
Google has been unhelpful in turning up solutions to this problem, because most of the results I have found were just other people asking the same or a similar question, and then either no answer, or something I had already tried, with no indication of exactly what sort of options or settings I needed to give it in order to accomplish the task.
I am using the processing.core.jar from version 2.0b7, but I don't think that would make a difference, although I plan to try it with different versions if I can't figure out anything else.
A copy of my project folder can be found at https://www.dropbox.com/sh/1n4curhxbgi8fye/A5F6_l7xQu
All the data I have is stuff I've concatenated together from successive versions of the file at http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt
I've done a quick test on OSX and had to tweak your eclipse project a bit:
You are linking to .jar libraries using absolute path. I recommend using keeping libraries relative to the project
I ran into some memory issues and had to add a couple of compiler flags
Added a main method in Earthquaker.java to initialize as an application.
main looks like this:
public static void main(String[] args) {
PApplet.main(Earthquaker.class.getSimpleName());
}
In eclipse you can export a runnable jar via File > Export > Java > Runnable JAR file. Here are a couple of screenshots:
Personally I prefer using the "Copy required libraries into a sub-folder..." option in case I need to update some dependent .jar independent of the main application .jar.
For reference I've uploaded the modified eclipse project here(Java SDK will need to be changed). The exported runnable jar with a bash script is available here.
And here is the bash script itself which should run on Linux as well:
java -Xms128M -Xmx1024M -jar Processing-DataVisualization.jar
Pretty cool project btw.
Create a simple jar. Create a batch file and specify the class path. Save the batch file. Runnin the batch file will run the app
#ECHO OFF
set CLASSPATH=%CLASSPATH%;myjar1.jar;myjar2.jar;
java mypackage.MyClass
Related
It's hard to explain, but I'll try my best.
There's a .jar file that opens up a GUI for a tournament environment. It's independent and I'm not given the source code. I need to code an agent in Java that competes in the tournament. When the .jar file opens, I can specify the path to my agent's class files in the GUI. This works fine. But I'm not sure how to debug this because the .jar file doesn't open in eclipse. I tried using external tools, which seems to run the .jar file but the GUI doesn't open up, so I can't specify the path to the agent. The tournament environment documentation doesn't really provide instructions to operate it without the GUI, so I really need to use just the GUI. Any way I can run this file through eclipse, so I can see how my own agent works with the environment and test/debug accordingly?
Additional info - this .jar also acts as a library which I was able to import into Eclipse without any issues.
It's hard to tell all of what's going on here, but there are a few things that can help.
First, you can start your app with the jar using command-line options like this:
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8453,server=y,suspend=n
Note that if you need to debug the startup code, you'll need to set "suspend=y", so the app will pause startup until you connect from the debugger.
In Eclipse, connect on port 8453.
Second, stepping through code that you don't have the source code for is not insurmountable. Install the "jd-eclipse" plugin, which you can get at http://jd.benow.ca/ . That will make that possible.
I've been using the JAD Eclipse plugin to reverse engineer jar libraries on the fly.
http://jadclipse.sourceforge.net/wiki/index.php/Main_Page
However, it is worth to note that the decompiled source code does not exactly match the line numbers in stack traces.
I'm pretty new to programming, so this should be an easy one. I'm switching from eclipse to netbeans and I am trying to add libjinput-osx.jnilib to my working directory. I have step by step instructions for eclipse, but not netbeans. I'm about 2.5 hours and 65 google searches in and I still cant find the answer to these two basic questions I have.
What exactly is a working directory in java?
How do you add a .jnilib file to your working directory in netbeans?
My end goal is to get an xbox controller to control a game of snake I wrote. I am trying to use JInput and this tutorial. In order to compile properly on OSX I need to put libjinput-osx.jnilib in the "working directory".
The "working directory" is the location where the application is working in...cryptic huh ;)
Typically it's the launch location for the app, although this can be modified through flags and other process.
In Netbeans, the working directory is typically the root directory of the project (which contains the src and nbproject folder), but this can be changed via the project properties.
One of the simplest ways to find the working directory at run time (this is useful for testing) is to do some thing like...
System.out.println(new File(".").getAbsolutePath());
There are two aspects to this question.
When you run a command from the command line, the "working directory" is the directory you were in when you ran the command. The instructions that you are reading say to put the native library there because Java's default search path for native library includes the current directory. Alternatively, you could add a -Djava.library.path=... option to the java command to set the search path explicitly.
When you run a command from within Eclipse ... or NetBeans ... the IDE's launcher will set the appropriate JVM parameters to include the project's native library directory on the search path. You need to put the library in THAT directory. This wiki page explains what you need to do for NetBeans.
It looks like what you're really trying to do is load a native library. Try this:
public class MainClass {
static {
System.loadLibrary( "Your_native_lib_file_name" ); // Note: do not include the file extension!
}
}
You might also try -Djava.library.path=/exact/path/to/dir/
Answer copied from here:
Java can't seem to find my native libraries
I have a 202 instructor who says that he feels its fine to use netbeans or eclipse but that for the final project he wants a file that he can load on his xp (I'm not sure why xp) machine, compile and run with the following commands:
javac *.java
java FinalProject
Up to this point I have been editing in a simple text pad like program and missing netbeans but to be fair I can't figure out how to code in netbeans in such a way that I get a generic set of files with no handily added code. If anyone could tell me how to convince netbeans that I don't need packages, ant build, team work software, and a bunch of netbeans helpful files lying around in my code I would really really appreciate it.
First you must get better understanding about IDE. Refer here
for NetBeans and Eclipse
When we write a simple program in few lines we can do with notepad and compile with javac. If we go for a big project there are lot of stuff and features required like
Adding external lib
UI Frame work
Identifying syntax error
Easy compilation, debugging and execution
Writing unit test etc.,
In netbeans, you just take "src" folder and use it.
So with netbeans all the source code files get put into a src directory. This contains nothing other than source files. In order to compile it using javac *.java you should place all your java files in the <default package> or without a package(Netbeans will warn that this is bad practice but you can ignore that for now). To run the program using java FinalProject you need to make a java file called FinalProject.java(with a class called FinalProject. You can create any additional classes in external files as long as they all go in the same <default package>.
Netbeans' scripts will just make it easier for you to compile and test your code. And to submit you just need to submit all the files in the src folder.
Also, as a side note, If you are creating GUI's using netbeans, you should probably use GridBagLayout rather than the default layout as that adds an additional library that will mean that your instructor's compilation will fail.
I created a runnable JAR with Eclipse for a small SLick2D game. No matter what settings I tried, I always received some sort of error, whether it be UnsatisfiedLinkError, or some class not being found.
I tried JARSplice, but that didn't work either.
Can anyone give me the steps to creating a runnable jar out of an Eclipse project?
The first thing you need is to somehow include the native libraries. You'll find them in the .zip you download from the lwjgl site.
I can recommend using JarSplice to package them. Make sure that when you specify what class it is supposed to run you do not use the default package (This is bad practice anyway). Specify the whole package path (e.g. package1.package2.Main), and it should run.
Use the packaged JAR generated by eclipse as your "input" jar of jarSplice.
If you use your command prompt to try and run your .jar after jarsplicing it, or using the manifest method, or whatever, you would go to the directory your .jar is in and type
java -jar YourGameNameHere.jar
This will give you the errors on why it will not run.
I am new to Java (and Eclipse) but I have used .NET (and Visual Studio) a fair amount. I also know about compiling C/C++ code and things like that. I know that at the end I get either an EXE or a nice binary file that can be run from the command line.
I have been making a Java utility that uses some external libraries. I need to compile this into an executable that I can run from the command line on a unix machine, but I cannot find any way to do this.
I can build and run/debug in Eclipse, but that is no use to me as this code will be run on a webserver. I just need all the dependancies compiled in to one file but after hours of searching on Google, the best thing I could find was the Fat-JAR plugin for Eclipse and after using that I just get the following error when I try to run the file:
Exception in thread "main" java.lang.NoClassDefFoundError: Network/jar
This is really confusing me and as it is such an essential thing to be able to do I am sure I must be missing something blindingly obvious, but as I said, after hours of searching I have gotten nowhere.
I really appreciate any help you can give me. Thanks.
If you build your java app using Maven (which can be done with every major IDE), then you can use the maven Shade Plugin to build a shaded jar file; this is a jar file with all of its dependencies included.
A shaded jar can be run from the command line like this:
java -jar myjar.jar command line options
You're doing something standard and you're using eclipse. This means, in your case, Maven is your friend. Download and install the M2Eclipse plug-in. Maven is best at managing dependencies. So, creating a jar with dependencies included will be very, very straight forward. There are thousands of examples on the web and in StackOverflow. If you have problems setting it up, comment on this and I can point you in the right direction.
Sounds like your class path on the server needs to be modified to pick up the jar file containing the Network class. How are you executing your program? What path(s) are you putting in the -cp option?
If you are not sure how to find out the contents inside a jar file, run jar tf , this will list the packaged classes. Validate that one of the jars in your CLASSPATH has that class it says missing.
Give us more details and we can help solve it.
I think I should first explain some basics. A Java class can be run as an application if it has a public static void main(String[] args) method. If it has this method, you can run it from command line as:
java my.package.MyClass <attributes>
Before launching your app, you need to make sure that all required .jar files (and the root of your own class folders, if you did not make a jar from your classes) are in the CLASSPATH environment variable.
These are the absolute basics. When you are building a more complex app, or an app for distribution, you'll probably use maven or ant or some other tool that makes your life easier.