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.
Related
I am trying to veer away from writing most of my Java code in Eclipse and I'm coming up with small projects for myself to work on in order to a. become a better Java programmer and b. learn how to organize my applications (in both terms of code and directory structure).
I noticed that I make plenty of small, incremental changes to classes then to recompile and run my whole application. I'm slightly familiar with Makefiles from a course I took in C++, and I'm less familiar with Build Systems (Maven, Ant). Regarding this mater, here are a few things I'd appreciate help with:
First of all, is there a way that I can write a little file that separates where my .class files are saved during javac *.java?
Say I want to put all my .class files in a /bin folder
In that file, is there a command I can write to simplify the javac *.java and java [class name here...] process?
I know that this process is relatively simple already, but what I want to know is can I write something that will allow me to run commands along the lines of myExec build (compile and save all my java files) myExec run (run my application)
Finally, is there a simple Build System that I can/should learn to use that will allow me to accomplish this? Or am I confusing the point of a Build System.
Look at Maven or Gradle, it automatically separates the source file and class files.
Manual build script writing is waist of time really.
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
Background
I am writing a program that will do some bulk renaming of members and functions in a directory of java source code to de-obfuscate the code based on a look-up table .csv file passed in to the program.
What this is for is the source code I have was written against a obfuscated jar. I have a de-obfuscated version of the jar that was run through a customized version RetroGaurd and I would like to parse the mapping file that was passed in to RetroGaurd to de-obfuscate the function calls my source code makes in to the jar. If I just compile my code and run it through RetroGaurd too when I decompile I loose all of my nice commenting and formatting (unless there is a option on RetroGaurd that I missed).
Problem
I found the Abstract Syntax Tree parser built in to Eclipse and it looks perfect for my uses, however I am not planning on writing my program as a plugin for Eclipse, this is going to be a stand alone jar that can be run on any machine.
My main concern is as I write my code I am getting a lot of dependencies on internal jars that Eclipse uses. I know that if I conform to the EPL for the library jars I will have no issues distributing it, but I am concerned about this project getting bigger and bigger as I write it as more and more jars from Eclipse's SDK are required.
Are there any other projects out there that would give me the ability to parse Java source code to do find and replace reliably like AST will allow me to, or is there a way to use RetroGaurd (or a program like it) to run the same de-obfuscation but keep my comments and functions the same without needing to run the de-obfuscated program though a de-compiler afterwards?
If you're worried about the need to run Eclipse GUI to execute your code, then you could consider running the plugin in headless mode. This would allow your plugin to be run from command line. See this SO thread.
You could also use any other open source java compiler. For e.g., openjdk's Java compiler. Please refer to the Resources section.
Hope it helps.
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.
In the past, I have used JCreator to develop my java applications. I wanted to try Eclipse and see its IDE.
On JCreator, I could just open a java file and run it in the command prompt. On Eclipse, I cannot find out how I can compile and run a java file written by someone else without first creating a project, creating a new java class and then copy and pasting the code from the file.
I cannot even figure out how to import a java file into the project.
So my questions:
1. How can I open, compile and run a java file without first creating a java project.
2. How can I import a java file into a project I already have.
3. How can I run the program in command prompt, instead of on the console that is in Eclipse, (update: to be more clear) directly from the Eclipse.
Thank you.
1/ Do not forget scrapbook page (also presented here)
In theory, you could copy a class in it, but since that class is actually encapsulated into a "main invisible" class, as an inner class, it would not support any static methods in it.
However, for a quick chunk of code, it does the trick just fine.
(from this Eclipse tutorial)
3/ Since you want it run directly from eclipse, use as indicated in this thread, an External tool
That External Tool would run C:\WINDOWS\system32\cmd.exe with working directory ${container_loc}
More details in this article "How do I open a Windows Command Prompt in my console ?".
(source: avajava.com)
That will give:
(source: avajava.com)
As far as I know, you can't
Right click project > Import
With respect to your platform, something roughly equivalent to: java <classname>. (Make sure java is in your path, otherwise use the absolute path to the it.)
A useful feature is available in Eclipse since version 3.4: you can paste the text of a Java class into a Java project (copy the content of the class, select the project or source folder, paste). This will create an appropriately named file, in the correct package. This is probably the easiest way to import a single class.
2) Use the "Import" command. Ensure the java file goes to the "src" directory.
3) One way is to export your classes to a JAR file and then run the JAR file at the command prompt (e.g. java -jar file.jar)