Showing posts with label jar. Show all posts
Showing posts with label jar. Show all posts

Tuesday, August 21, 2018

How to build a jar from a multi-module project when using Gradle?

Leave a Comment

I'm working on a multi-module library project which I build with Gradle. I have a dependency to another module of this project in my dependencies section:

dependencies {     compile project(':my-other-module') } 

My problem is that I want to build a .jar file which only contains the local modules in the final file, not its transitive dependencies. I tried this:

jar {     from project(':my-other-module').configurations.compile.collect { zipTree it } } 

but this added all the transitive dependencies as well. I want to create a .jar which only contains my own files, so the users of this library can have their own versions of transitive dependencies. How can I do so?

1 Answers

Answers 1

Gradle has a compile-only dependency concept, similar to Maven's provided scope:

Compile-only dependencies are distinctly different than regular compile dependencies. They are not included on the runtime classpath and they are non-transitive, meaning they are not included in dependent projects.

The dependencies you don't want can be declared in the compileOnly configuration, rather than compile, eg:

dependencies { compileOnly 'javax.servlet:servlet-api:2.5' }

compileOnly is not even visible to unit tests, by default. We change this in a common gradle snippet which we include in each build:

// compileOnly isn't visible to tests by default, add it plugins.withType(JavaPlugin).whenPluginAdded {     sourceSets {         test.compileClasspath += configurations.compileOnly         test.runtimeClasspath += configurations.compileOnly     } } 

For the second part, for which I believe you want to create a single "fat" jar, I would suggest creating your jar using the very good Shadow Plugin, rather than manually extending the jar task. By default, the shadow plugin will not include anything in the compileOnly configuration in the resulting jar.

Read More

Friday, December 15, 2017

How to install a compiled by Gradle jar into the local Gradle Repository files-2.1 instead of the Maven repository?

Leave a Comment

In my build.gradle, I added the plugin:

apply plugin: 'maven' 

Then using “gradle install” I can copy the resulted jar into the maven repository : ~/.m2/repository

However, my Gradle repository resides in ~/.gradle/caches/modules-2/files-2.1. How can I install the jar into this repository?

4 Answers

Answers 1

mavenLocal() is resolved like this:

In order to make use of a non-standard local maven repository, you can use the following configuration in your build.gradle:

repositories { maven { url '/Users/manuelj/apache/maven/repository' } }

Answers 2

A build.gradle sample to create a Jar file along with its logback dependencies. using mavenlocale() apply plugin: 'java'

apply plugin: 'eclipse'

version = '1.0'

sourceCompatibility = 1.7

target Compatibility = 1.7

//create a single Jar with all dependencies

task fatJar(type: Jar) {

 manifest {      attributes 'Implementation-Title': 'Gradle Jar File Example',          'Implementation-Version': version,          'Main-Class': 'com.mkyong.DateUtils' } baseName = project.name + '-all'  from { configurations.compile.collect { it.isDirectory() ? it :  

zipTree(it)

}

} with jar }

//Get dependencies from Maven central repository

repositories {

mavenCentral() 

}

//Project dependencies

dependencies {

compile 'ch.qos.logback:logback-classic:1.1.2' 

}

Reference create a Jar file along with its logback dependencies.

Answers 3

If you insist on manipulating the cache, then your best bet is to write a shell script that will manually replace latest JAR in the cache.

The reason is that Gradle does not come with this functionality built-in, as Gradle uses notion of "local cache" in a strict sense, as opposed to "local repository" which is used by Maven.

The difference is that you are never supposed to save files to local cache manually.

To solve your problem the recommended way: Suppose that project A is a dependency of project B. Then you can call publishToMavenLocal command in project A to refresh the depedency. Add mavenLocal() repository in gradle.build of project B, so every time you build project B, Gradle will check the local repository when resolving the dependency A.

Answers 4

What worked for me is gradle install -Dmaven.repo.local=the/path/of/the/folder.

I don't know which IDE you are using but in eclipse you can add a new Run Configuration, in Gradle taks add install and in program arguments -Dmaven.repo.local=the/path/of/the/folder.

Read More

Thursday, December 7, 2017

Eclipse Jar-in-Jar fails to find a joda.time class

Leave a Comment

Eclipse has 3 runnable JAR export methods. One of them does not work in my case. I want to stop using the export method that makes a library sub-folder and switch to a single JAR.

In all cases my invocation is in a script, with a few script variables such as $MEMORYOPTIONS

java $MEMORYOPTIONS -enableassertions -classpath VARIOUS-SHOWN-BELOW topLevelDomain.domain.packageName.className $1 $2 $3

Firstly...

I have success with the following export method and the class path as shown.

export > runnable jar > extract required libraries

-classpath /home/user/workspace/project/project1.jar

I have a reason for not wanting to use this single JAR. (It is because unpackaged third party packages expose files with duplicate names so I get annoying warnings. Example: A file called License.txt is in several packages.)

Secondly...

As already mentioned I also have success with the following "library sub-folder" export method and class path as shown.

export > runnable jar > copy required libraries into a sub-folder

-classpath /home/user/workspace/project/project1.jar:/home/user/workspace/project/project1_lib/*

(Edit: As it turns out the JAR has a manifest that points to the project1_lib subfolder so the class path can be simplified to omit that. Just delete the part after the colon (:) separator from the class path.)

Thirdly...

I interpret "package required libraries" to mean a JAR-in-JAR export. Invoked with the class path shown, this export results in a failure to find the class.

export > runnable jar > package required libraries

-classpath /home/user/workspace/project/project1.jar

The error is:

Exception in thread "main" java.lang.NoClassDefFoundError: org/joda/time/ReadablePartial

How do I get this particular type of Eclipse export to work? I have already uninstalled Eclipse (Mars) and reinstalled. I have also removed the org.joda.time package and added it back. The problem persists.

3 Answers

Answers 1

Did you consider creating an uber jar ?

With maven you just need to add the following plugin definition and use the command mvn package

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.2</version> <executions>     <execution>         <phase>package</phase>         <goals>             <goal>shade</goal>         </goals>         <configuration>              <filters>                 <filter>                     <artifact>joda-time:joda-time</artifact>                     <includes>                         <include>**</include>                     </includes>                 </filter>                 <filter>                     <artifact>*:*</artifact>                     <excludes>                         <exclude>META-INF/*.SF</exclude>                         <exclude>META-INF/*.DSA</exclude>                         <exclude>META-INF/*.RSA</exclude>                     </excludes>                 </filter>             </filters>         </configuration>     </execution> </executions> </plugin> 

Hope this helps.

Answers 2

You need to call the bundled JarRsrcLoader with your class as an argument:

java $MEMORYOPTIONS -enableassertions  -classpath /home/user/workspace/project/project1.jar  org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader topLevelDomain.domain.packageName.className 

However, this doesn't allow you to pass arguments ($1 $2 $3) to the called class.

Answers 3

You should launch your app using java's -jar option. Something like this:

java $MEMORYOPTIONS -enableassertions -jar /path/to/project1.jar $1 $2 $3 
Read More

Monday, October 23, 2017

How a jar can propagate a vulnerability in a web application where it is used?

Leave a Comment

I have a Spring MVC web application protected with Spring Security. Life seems so calm until I was forced to do a Static Application Security Testing (SAST) and the tool threw a bunch of security issues. Have a look at here:

enter image description here

I have gone through all CVEs and got a rough picture about the vulnerabilities. I have a few queries:

  1. How a web application is vulnerable to such exploitation, when a security framework like (Spring Security) is integrated with it?

  2. Can I ignore all those vulnerabilities since Spring Security might have some sort of workaround for all those vulnerabilities?

1 Answers

Answers 1

From the Spring Security manual:

Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications.

Think of spring security as an authentication framework, it covers one piece of the security puzzle.

As an example, let's have a look at the #1 of the OWASP Top 10 Application Security Risks: A1 - Injection
Assume you use a jar for accessing an SQL database (e.g. hibernate) and it has an injection vulnerability, then your application could be vulnerable as well. However even if hibernate doesn't have any security bugs, if a programmer concatenates an SQL query together without correctly escaping the user input the application is vulnerable to an injection attack.
Spring security doesn't protect your application from either of these injection attacks.

If a jar has a vulnerability and you are calling the vulnerable methods/features then your app may also have that vulnerability, it depends a lot on what the vulnerability is and how its executed and how your application is configured to use the jar.

For a quick look over the other OWASP Top 10 Application Security Risks:
A1-Injection - No protection from Spring Security
A2-Broken Authentication and Session Management - Spring Security can help manage some of these, however a miss configured spring security will expose these.
A3-Cross-Site Scripting (XSS) - No protection from Spring Security
A4-Insecure Direct Object References - No added protection from Spring Security (Spring Security gives you the tool to manage this)
A5-Security Misconfiguration - No protection from Spring Security
A6-Sensitive Data Exposure - Spring Security can assist with this however it also depends a lot on how you store and manage your data (E.g. log files)
A7-Missing Function Level Access Control - If the access control has been missed, Spring Security can't help you, however spring security makes it easy to add these
A8-Cross-Site Request Forgery (CSRF) - Spring Security (depending on how your application is configured) will assist you or even manage this risk for you.
A9-Using Components with Known Vulnerabilities - This is the CVE's you have listed in your question - No protection from Spring Security
A10-Unvalidated Redirects and Forwards - Spring Security could be used to manage this however it doesn't protect your application from this out of the box

The list of CVEs found during the STAT of your application is an example of A9-Using Components with Known Vulnerabilities have a look at the OWASP wiki for more information.

Example Attack Scenarios

Component vulnerabilities can cause almost any type of risk imaginable, ranging from the trivial to sophisticated malware designed to target a specific organization. Components almost always run with the full privilege of the application, so flaws in any component can be serious, The following two vulnerable components were downloaded 22m times in 2011.

  • Apache CXF Authentication Bypass – By failing to provide an identity token, attackers could invoke any web service with full permission. (Apache CXF is a services framework, not to be confused with the Apache Application Server.)
  • Spring Remote Code Execution – Abuse of the Expression Language implementation in Spring allowed attackers to execute arbitrary code, effectively taking over the server.

Every application using either of these vulnerable libraries is vulnerable to attack as both of these components are directly accessible by application users. Other vulnerable libraries, used deeper in an application, may be harder to exploit.

Note from the last paragraph above, the deeper the component (jar) is the harder it is to exploit, however, that doesn't mean a determined entity can't exploit them.

In summary, Spring Security is a great tool for managing authentication and access-controls in your application but it isn't a magic bullet to fix all security problems.

Read More

Friday, September 15, 2017

Upgrade J2ee project to latest libraries

Leave a Comment

I got a task to tidy up a j2ee application and upgrade all its libraries for security purposes (some older jars got on a security concern report)

we are using maven and I have couple of questions :
Is it possible to find unused jars?
How to go about upgrading the libraries?
If library A is upgraded how to find related libraries minimum version?

m2/aopalliance/aopalliance/1.0/aopalliance-1.0.jar m2/asm/asm/3.3.1/asm-3.3.1.jar m2/cglib/cglib-nodep/2.2.2/cglib-nodep-2.2.2.jar m2/cglib/cglib/2.2.2/cglib-2.2.2.jar m2/com/google/code/gson/gson/2.7/gson-2.7.jar m2/com/ibm/icu/icu4j/53.1/icu4j-53.1.jar m2/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.jar m2/commons-beanutils/commons-beanutils/1.9.2/commons-beanutils-1.9.2.jar m2/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar m2/commons-fileupload/commons-fileupload/1.3.1/commons-fileupload-1.3.1.jar m2/commons-io/commons-io/2.4/commons-io-2.4.jar m2/commons-logging/commons-logging/1.2/commons-logging-1.2.jar m2/junit/junit/4.11/junit-4.11.jar m2/org/apache/commons/commons-collections4/4.0/commons-collections4-4.0.jar m2/org/apache/commons/commons-digester3/3.2/commons-digester3-3.2.jar m2/org/apache/commons/commons-email/1.3.3/commons-email-1.3.3.jar m2/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar m2/org/apache/logging/log4j/log4j-api/2.1/log4j-api-2.1.jar m2/org/apache/logging/log4j/log4j-core/2.1/log4j-core-2.1.jar m2/org/apache/taglibs/taglibs-standard-impl/1.2.1/taglibs-standard-impl-1.2.1.jar m2/org/apache/taglibs/taglibs-standard-spec/1.2.1/taglibs-standard-spec-1.2.1.jar m2/org/mongodb/mongo-java-driver/2.12.4/mongo-java-driver-2.12.4.jar m2/org/mongodb/morphia/morphia/1.3.2/morphia-1.3.2.jar m2/org/slf4j/jcl-over-slf4j/1.7.7/jcl-over-slf4j-1.7.7.jar m2/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar m2/org/springframework/data/spring-data-commons/1.8.0.RELEASE/spring-data-commons-1.8.0.RELEASE.jar m2/org/springframework/data/spring-data-mongodb/1.5.0.RELEASE/spring-data-mongodb-1.5.0.RELEASE.jar m2/org/springframework/spring-aop/4.0.5.RELEASE/spring-aop-4.0.5.RELEASE.jar m2/org/springframework/spring-beans/4.0.5.RELEASE/spring-beans-4.0.5.RELEASE.jar m2/org/springframework/spring-context/4.0.5.RELEASE/spring-context-4.0.5.RELEASE.jar m2/org/springframework/spring-core/4.0.5.RELEASE/spring-core-4.0.5.RELEASE.jar m2/org/springframework/spring-expression/4.0.5.RELEASE/spring-expression-4.0.5.RELEASE.jar m2/org/springframework/spring-tx/3.2.9.RELEASE/spring-tx-3.2.9.RELEASE.jar m2/org/springframework/spring-web/4.0.5.RELEASE/spring-web-4.0.5.RELEASE.jar m2/org/springframework/spring-webmvc/4.0.5.RELEASE/spring-webmvc-4.0.5.RELEASE.jar m2/xalan/serializer/2.7.1/serializer-2.7.1.jar m2/xalan/xalan/2.7.1/xalan-2.7.1.jar m2/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar 

1 Answers

Answers 1

  • Is it possible to find unused jars?

    Yes!, you can use the Apache Maven Dependency Plugin.

    You can do a mvn dependency:analyze -DignoreNonCompile to find unused but declared and used but undeclared dependencies. Please check the full documentation because you can customize exclusions, in what phase you want to execute the verification and other topics within this plugin.

    You can be as strict as you want, check the goals available for this plugin, using <goal>analyze-duplicate</goal> you can also catch duplicated dependencies, for example if you want your build to fail on "dependency errors" you can define this plugin in your pom.xml like:

    <plugin>   <groupId>org.apache.maven.plugins</groupId>   <artifactId>maven-dependency-plugin</artifactId>   <executions>     <execution>       <id>analyze-dependencies</id>       <goals>         <goal>analyze-duplicate</goal>         <goal>analyze-only</goal>       </goals>     </execution>   </executions>   <configuration>     <failBuild>true</failBuild>   </configuration> </plugin> 
  • How about upgrading the libraries?

    Yes! For this task you can use the Versions Maven Plugin.

    To find new dependency updates you can use mvn versions:display-dependency-updates, it will give you a list of the latest versions for the dependencies in your pom.xml

    You can also do a mvn versions:display-plugin-updates to find plugin updates.

    By default this will be performed recursively, in case you don't want to have it recursive you can use the -N flag.

    Putting it all together: mvn -N versions:display-dependency-updates versions:display-plugin-updates

Read More

Tuesday, May 30, 2017

Proper packaging of runnable Jar project in netbeans

Leave a Comment

So my task is to create a small program that displays a list of media files and run these media files with default OS media player separately.

My current solution was to create a package that holds all media files, something like:

-com.media        |_a.mp4        |_b.mp4 

The following code copies to a temp dir the selected mp4, then runs the default os media player:

public File copyTempMedia(File tempAppFolder, String videoName) {      URL f = getClass().getResource(String.format("%s/%s", Constants.MEDIA_LOCATION, videoName));     File from = new File(f.getPath());     File to = new File(tempAppFolder.getAbsolutePath());      try {         FileUtils.copyFileToDirectory(from, to);     } catch (IOException ex) {         Logger.getLogger(MediGUIModel.class.getName()).log(Level.SEVERE, null, ex);     }     System.out.println("Temp video copied: "  +  to.getAbsolutePath() + "/" + to.getName());     return to; }  public void triggerMediaPlayer(String fileLocation) {     System.out.println("Triggering media player: " + fileLocation);     try {         if (OPERATIN_SYSTEM.contains("Linux")) {             Runtime.getRuntime().exec("sh -c " + fileLocation);         } else if (OPERATIN_SYSTEM.contains("Windows")) {              Runtime.getRuntime().exec("cmd /c " + fileLocation);         }     } catch (IOException ex) {         Logger.getLogger(MediGUIModel.class.getName()).log(Level.SEVERE, null, ex);         ex.printStackTrace();     } } 

When I run the program through Netbeans it works as espected, but when I do a clean/build the run the .jar created from the build, the media file doesn't seem to be read, so my questions are:

  1. Why does it work through Netbeans and not through build .jar ?
  2. Is this the best solution to this problem ?
  3. Should I package the media differently ?

Thanks in advance.

Edit

So after running through console instead of double clicking jar, is get a null pointer exception in the line where I read the file:

URL f = getClass().getResource(String.format("%s/%s", Constants.MEDIA_LOCATION, videoName)); 

Why does it work in Netebeans but not on build/jar ?

Is there another place in the jar I could place the media files, so that they are read with no problem through getResource or getResourceAsStream ?

4 Answers

Answers 1

When you run the project in NetBeans, it isn't running the executable jar like java -jar yourproject.jar. Instead it sets the classpath to build/classes sort of like java -cp build/classes com.media.YourMainClass. This means your video files are actual files located in yourproject/build/classes/com/media, and they can be accessed as normal files in the filesystem and copied like a normal file. When you run from the jar, the files are packed in the jar file and can't be copied using simple file copy commands.

Instead of getting the URL by calling getClass().getResource(), try getting an InputStream by calling getClass().getResourceAsStream(). You can then write a simple loop to copy the bytes from the input stream to your temporary file.

Answers 2

Ok so I found a solution:

  1. Create a separate project with media.*.mp4.
  2. Export as Jar library.
  3. Import library to desktop app.
  4. Make sure library is in classpath.

This solution works for me...

If anyone has a better solution, happy to hear, hopefully before bounty is up :)

Answers 3

This snippet may be helpful:

    BufferedInputStream result = (BufferedInputStream) getClass().getResourceAsStream("/com/media/a.mp4");     byte[] bytes = new byte[4098];     try {         result.read(bytes);     } catch (IOException e) {         e.printStackTrace();     }     System.out.println(new String(bytes)); 

You'll need to read the bytes in a loop or something but that should work without needing a separate jar.

Answers 4

I think it's not a good idea to put your media files in the jar because you need to rebuild the project if you want to change one and the jar size will grow.

Use:

File from = new File(String.format("%s/%s", Constants.MEDIA_LOCATION,videoName)); 

To load your files from the same folder as the jar.

If you want to keep the medias in the jar, create a Maven project and put the mp4 in src/main/resources. Use maven to create a fat jar and the src/main/resources will be included in the jar. See 'maven-shade-plugin' to configure the pom.xml and https://www.mkyong.com/maven/create-a-fat-jar-file-maven-shade-plugin/

Then you can use the others maven's great properties!

See Reading a resource file from within jar

Edit

After some tries, i can't get it right with 'getResource' from the jar. The path you get from within the jar is like:file:/C:/.../JavaApplication4/dist/JavaApplication4.jar!/test.txt and not recognized as a valid filesystem path.

You can use 'getResourceAsStream' and copy the file from the jar to the local folder.

InputStream in; OutputStream out; IOUtils.copy(in,out); in.close(); out.close(); 
Read More

Wednesday, May 24, 2017

How to deploy JAR files to existing webapp subdirectory?

Leave a Comment

Let's say I have a very ordinary web app deployed via mywebapp.war, generated by Maven:

webapps   |   |--mywebapp.war   |--mywebapp        |        |--images        |--js        |--jsp        |--jardeploy        |--META-INF        |--styles        |--WEB-INF 

Now I would like to deploy myjarfile1.jar and myjarfile2.jar (or more) in webapps/mywebapp/jardeploy. They are artifacts of another Maven project, not the one that makes the war. They are also not jars that mywebapp uses, which would be under WEB-INF/lib, but rather downloadable jars built separately and not part of the mywebapp source code.

Is there a way to package an archive bundling the two or more jars in Maven which, when dropped in webapps will get deployed not in default webapps/jardeploy but in webapps/mywebapp/jardeploy? It would be the same as though I took the jars and copied them in that directory but I would like to follow the standard app server deployment protocol by dropping a generated artifact in webapps rather than the hacky former approach. I actually want a formal artifact (just like the war) instead of a post deploy add-on. Is there a way to tell (perhaps in the manifest) that it needs to unpack the jar and put it in that directory, if that directory exist?

The container shouldn't matter but it is Tomcat 7.

2 Answers

Answers 1

This looks like a standard use-case for maven-war-plugin and extra resources, unless I'm missing something. For example here (See section Configuring web resources) tells you that you can include additional resources in your war build (and this is what your two jars are to me : additional resources)

If this doesn't work for you then maven-assembly-plugin allows you to specify a much more flexible format.

Answers 2

You could create a webapp with a WebListener that copies the jar files to mywebapp/jardeploy directory. So when this application is deployed in your container it will copy the jars to the place you want.

I tested and it works! Supposing you have created this new webapp and have put the jars in src/main/webapps/jars directory, the WebListener look likes this:

@WebListener public class Deployer implements ServletContextListener {      public void contextInitialized(ServletContextEvent sce) {         String realPath = sce.getServletContext().getRealPath("/jars");         try {             Files.copy(new File(realPath + "/myjarfile1.jar").toPath(),                  new File(System.getProperty("catalina.base")+"/webapps/mywebapp/jardeploy/myjarfile1.jar").toPath());         } catch (IOException e) {             e.printStackTrace();         }     }      public void contextDestroyed(ServletContextEvent sce) {         System.out.println("On shutdown web app");     } } 

This code is just a proof of concept and can be enhanced, but it servers to its purpose. It only copies one jar (myjarfile1.jar) to /webapps/mywebapp/jardeploy. PS: I created this new webapp using maven archetypes.

Read More

Thursday, February 2, 2017

Translate jardesc content into jar-command

Leave a Comment

I am making some WebFilters for our WebLogic server and I've got everything up and running.

The problem is how I package the filters into jar-files. If I use the following jardesc-file and create the jar-file from Eclipse, everything is working fine and WebLogic has no problems loading the webfilter class. But as soon as I try to manually create the jar-file using just jar.exe I am hitting ClassNotFoundExceptions when loading the webcontainer in WebLogic.

Working jardesc-file:

<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?> <jardesc>     <jar path="C:/Workspace/Java/Jars/jars/corsfilter.jar"/>     <options buildIfNeeded="true" compress="true" descriptionLocation="/CorsFilter/corsfilter.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>     <storedRefactorings deprecationInfo="true" structuralOnly="false"/>     <selectedProjects/>     <manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">         <sealing sealJar="false">             <packagesToSeal/>             <packagesToUnSeal/>         </sealing>     </manifest>     <selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">         <file path="/CorsFilter/.project"/>         <file path="/CorsFilter/.classpath"/>         <javaElement handleIdentifier="=CorsFilter/src"/>     </selectedElements> </jardesc> 

Current jar-command:

jar -cvf corsfilter.jar .project .classpath -C .\bin dk\akait\filters\cors\CorsFilter.class 

The jar-command creates a jar-file that seems to be equivalent to the one generated using the jardesc-file in Eclipse, except for what looks like some kind of symbolic link to the META-INF-folder in the root of the jar-file.

Content of working jar-file: Working jar-file

Content of non-working jar-file enter image description here

Can anyone explain what the right command for executing jar.exe is, given the jardesc-file?

Or

Can anyone explain what the META-INF file in the not working jar-file is?

Updated with output of jar-command run using jdk-1.8.0_111 Output of jar-command

1 Answers

Answers 1

I don't think your command line is even correct. As according to jar output

Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...

And also http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jar.html

It is expect to be [manifest-file] and [entry-point] after [jar-file] name.

Try jar -cvf corsfilter.jar -C . .project .classpath -C .\bin dk\akait\filters\cors\CorsFilter.class

Read More

Wednesday, April 27, 2016

UnsupportedNodeException: Request for a node that is not part of the specified profile and components for this stream: viewpoint

Leave a Comment

I've been stuck on the same problem for some time and I don't know why I get the following Run-time error when I run my project.

Exception in thread "main" org.web3d.vrml.lang.UnsupportedNodeException: Request for a node that is not part of the specified profile and components for this stream: viewpoint     at org.web3d.vrml.renderer.DefaultNodeFactory.createVRMLNode(DefaultNodeFactory.java:730)     at org.web3d.vrml.renderer.ogl.OGLMainSceneBuilder.startNode(OGLMainSceneBuilder.java:147)     at org.web3d.vrml.renderer.ogl.OGLVRMLSceneBuilder.startNode(OGLVRMLSceneBuilder.java:514)     at org.web3d.x3d.jaxp.X3DSAVAdapter.startElement(X3DSAVAdapter.java:830)     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1364)     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2787)     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)     at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)     at org.web3d.parser.GeneralisedReader.parse(GeneralisedReader.java:261)     at org.xj3d.impl.core.loading.DefaultWorldLoader.loadNow(DefaultWorldLoader.java:156)     at org.xj3d.impl.core.loading.DefaultWorldLoader.loadNow(DefaultWorldLoader.java:203)     at org.web3d.vrml.scripting.browser.X3DCommonBrowser.createX3DFromURL(X3DCommonBrowser.java:264)     at org.web3d.vrml.scripting.external.sai.SAIBrowser.createX3DFromURL(SAIBrowser.java:843)     at xj3dtest.Xj3DTest.<init>(Xj3DTest.java:50)     at xj3dtest.Xj3DTest.main(Xj3DTest.java:56) 

My Java code for this is

package xj3dtest;  import java.awt.BorderLayout; import java.awt.Container; import static java.lang.Boolean.TRUE; import javax.swing.JFrame; import org.web3d.x3d.sai.Browser; import org.web3d.x3d.sai.BrowserFactory; import org.web3d.x3d.sai.X3DComponent; import org.web3d.x3d.sai.X3DScene; import java.util.HashMap;  public class Xj3DTest extends JFrame {      public Xj3DTest(String title) {          super(title);          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          // Setup browser parameters         HashMap requestedParameters=new HashMap();         requestedParameters.put("Antialiased",TRUE);         requestedParameters.put("TextureQuality","medium");         requestedParameters.put("PrimitiveQuality","medium");         requestedParameters.put("Xj3D_InterfaceType","SWING");         requestedParameters.put("Xj3D_NavbarShown",TRUE);         requestedParameters.put("Xj3D_NavbarPosition","TOP");         requestedParameters.put("Xj3D_LocationShown",TRUE);         requestedParameters.put("Xj3D_LocationPosition","TOP");         requestedParameters.put("Xj3D_LocationReadOnly",TRUE);         requestedParameters.put("Xj3D_ShowConsole",TRUE);         requestedParameters.put("Xj3D_OpenButtonShown",TRUE);         requestedParameters.put("Xj3D_ReloadButtonShown",TRUE);         requestedParameters.put("Xj3D_StatusBarShown",TRUE);         requestedParameters.put("Xj3D_FPSShown",TRUE);         requestedParameters.put("Xj3D_ContentDirectory","CurrentDirectory");         requestedParameters.put("Xj3D_AntialiasingQuality","low");         requestedParameters.put("Xj3D_Culling_Mode", "frustum");          System.setProperty("x3d.sai.factory.class", "org.xj3d.ui.awt.browser.ogl.X3DOGLBrowserFactoryImpl");         X3DComponent x3dComponent = BrowserFactory.createX3DComponent(requestedParameters);          Browser browser = x3dComponent.getBrowser();          Container cp = getContentPane();         cp.setLayout(new BorderLayout());         cp.add((javax.swing.JPanel)x3dComponent, BorderLayout.CENTER);          X3DScene scene = browser.createX3DFromURL(new String[] {"test.x3d"});          browser.replaceWorld(scene);     }      public static void main(String[] args) {         Xj3DTest frame = new Xj3DTest("Xj3D test");         frame.setSize(640, 480);         frame.setLocationRelativeTo(null);         frame.setVisible(true);     } } 

The X3D files that I need to pass through it so it displays contain a viewpoint and imageTexture url tags which are tested to cause the problem. When I delete those tags from within the X3D files, it does work but doesn't have the desired output as it seemed to be zoomed in and have no texture the the X3D file.

The Jars that I'm using are gluegen-rt, gluegen-rt-natives-linux-amd64, gluegen-rt-natives-windows-amd64, gluegen-rt-natives-linux-i586, j3d-core-1.3.1, jhall, joal, joal-natives-linux-amd64, joal-natives-windows-amd64, joal-natives-linux-i586, joal-all, joal-all-natives-linux-amd64, joal-all-natives-windows-amd64, joal-all-natives-linux-i586, xj3d.browser_2.1.0-nps, xj3d.cadfilter_2.1.0_nps, xj3d.2.1-3rdparty-nps, xj3d.2.1-nps, xj3d-core, xj3d-runtime, xj3d-script-base. The way that I've set the VM Options is by using -Xmx450M -Djava.library.path="C:\Users\matt\Documents\NetBeansProjects\jar" and I have added the library that contains all the Jars to the project.

EDIT It's still not working

EDIT#2

The two tags that are causing the problem are

<viewpoint centerOfRotation="7 1 0" position='10 0 40' orientation='0 0 0 1'></viewpoint>

<imageTexture url='"http://somewebsite.com/images/test.jpg"></imageTexture> Bare in mind that the above website isn't the website where the image is stored but it follows the same format.

EDIT #3

The code in the X3D file is now <viewpoint centerOfRotation="7 1 0" position='10 0 40' orientation='0 0 0 1'></viewpoint>

<imageTexture url="http://somewebsite.com/images/test.jpg"></imageTexture>

And I'm still getting the viewpoint error and I don't know how to fix it

1 Answers

Answers 1

For the first tag, the error was obviously a bogus single quote on url attribute.

For the second one, you could try using consistent quotes for all of your attributes, some parsers happen to fail on this.

Globally, you could start there:

  • check well-formedness of your XML with tools like this validator
  • check that your X3D is valid against the xsd declared in your XML header. There are a few references for validators on this page, but the most efficient way is still using an XML authoring tool of your choice.
Read More

Sunday, April 10, 2016

gradle to bundle nested jar dependencies into module output jar

Leave a Comment

How to make gradle to included some dependencies into module resulted jar as jar? i.e. to make jar with nested jar's e.g. in lib folder ?

This is not Android project, and this should be done for many modules in multi-module project, so fatJar, uberJar, shadowJar alike solutions seem not to fit.

1 Answers

Answers 1

You just need to add an additional from directive to include dependencies in your jar:

task jarJar(type: Jar) {     baseName = project.name + '-jarjar'     from { configurations.compile }     with jar } 
Read More